8 – YouTube Data API – Activities – list function

This is article 8 of the YouTube API With PHP series.

We will see how to work with YouTube Activities. An Activity is any task performed within a Channel like uploading a video or by a User eg.liking a video.  There are two functions available for Activities

1.list

 The Request URL is

GET https://www.googleapis.com/YouTube/v3/activities

 

Parameters

  • key (string) required. Your API key
  • part (string) required. One or all of the below, comma separated
    • “id”
    • “contentDetails”
    • “snippet”
  • (One of the filters below) required. (string)
    • channelId (string) unique id of a Channel
    • mine (boolean). Set to true to retrieve an authenticated user’s activities
  • maxResults (int) optional. max results to return. Valid range 0-50. default value is 5
  • pageToken (string) optional. used to move forward or backward through the results
  • publishedAfter (datetime) optional. Specifies a date and time after which an Activity occurred. Format is YYYY-MM-DDThh:mm:ss.sZ . You can also specify a date without time .
  • publishedBefore (datetime) optional. Specifies a date and time before which an Activity occurred. Format is YYYY-MM-DDThh:mm:ss.sZ . You can also specify a date without time
  • regionCode (string) optional. Specifies the two letter international code for the country for which results are NOT restricted. By default, most channels and users do not restrict display of their data in certain regions, so this parameter won’t have an effect. So if you specify regionCode=AU , it will show results which are allowed to be shown in Australia.

 

Example Requests

Fetch 5 results for a channel.

https://www.googleapis.com/YouTube/v3/activities?part=snippet,contentDetails,id&channelId=xxxx&maxResults=5&key=xxx

Fetch 5 results for a channel for all activities before 10 May, 2017

https://www.googleapis.com/YouTube/v3/activities?part=snippet,contentDetails,id&channelId=xxxx&maxResults=5&key=xxx&publishedBefore=2017-05-10T20:00:01.000Z

Fetch 5 results for a channel for all activities after 10 May, 2017

https://www.googleapis.com/YouTube/v3/activities?part=snippet,contentDetails,id&channelId=xxxx&maxResults=5&key=xxx&publishedAfter=2017-05-10T20:00:01.000Z

Fetch 5 results for a channel for all activities allowed to be shown in Australia

https://www.googleapis.com/YouTube/v3/activities?part=snippet,contentDetails,id&channelId=xxxx&maxResults=5&key=xxx&regionCode=AU

 

Response

 A successful request will return the following JSON response:

{
  "kind": "YouTube#activityListResponse",
  "etag": etag,
  "nextPageToken": string,
  "prevPageToken": string,
  "pageInfo": {
    "totalResults": integer,
    "resultsPerPage": integer
  },
  "items": [
    (Activity Resource)
  ]
}

The Response components are explained below:

  • kind (string) “YouTube#activityListResponse.”
  • etag (string) See ETags Explained section
  • nextPageToken (string) token for the next page
  • prevPageToken (string) token for the previous page
  • totalResults (int) total count of results obtained
  • resultsPerPage (int) results per page requested
  • items (array) array of Activity Resource items returned

 

Activity Resource

The items returned in an Activities list request are an array of Activity Resource objects. The JSON structure is shown below:

{
  "kind": "YouTube#activity",
  "etag": etag,
  "id": string,
  "snippet": {
	"publishedAt": datetime,
	"channelId": string,
	"title": string,
	"description": string,
	"thumbnails": {
  		(key): {
    			"url": string,
    			"width": unsigned integer,
    			"height": unsigned integer
  		}
	},
	"channelTitle": string,
	"type": string,
	"groupId": string
  },
  "contentDetails": {
	"upload": {
  		"videoId": string
	},
	"like": {
  		"resourceId": {
    		"kind": string,
    		"videoId": string,
  	}
	},
	"favorite": {
  		"resourceId": {
    			"kind": string,
    			"videoId": string,
  		}
	},
	"comment": {
  		"resourceId": {
    			"kind": string,
    			"videoId": string,
    			"channelId": string,
  		}
	},
	"subscription": {
  		"resourceId": {
    			"kind": string,
    			"channelId": string,
  		}
	},
	"playlistItem": {
  		"resourceId": {
    			"kind": string,
    			"videoId": string,
  		},
  		"playlistId": string,
  		"playlistItemId": string
	},
	"recommendation": {
  		"resourceId": {
    			"kind": string,
    			"videoId": string,
    			"channelId": string,
  		},
  		"reason": string,
  		"seedResourceId": {
    			"kind": string,
    			"videoId": string,
    			"channelId": string,
    			"playlistId": string
  		}
	},
	"bulletin": {
  		"resourceId": {
    			"kind": string,
    			"videoId": string,
    			"channelId": string,
    			"playlistId": string
  		}
	},
	"social": {
  		"type": string,
  		"resourceId": {
    			"kind": string,
    			"videoId": string,
    			"channelId": string,
    			"playlistId": string
  		},
  		"author": string,
  		"referenceUrl": string,
  		"imageUrl": string
	},
	"channelItem": {
  		"resourceId": {
  		}
	},
  }
}

An explanation of the various fields are given below:

  • kind (string) This value is always “YouTube#activity”
  • etag (string) See ETags Explained section
  • id (string) unique id of this Activity
  • publishedAt (datetime) Date and time of this Activity. (YYYY-MM-DDThh:mm:ss.sZ) format.
  • channelId (string) Id of the Channel associated with this Activity
  • title (string) title of the resource for this Activity
  • description (string) description of the resource for this Activity
  • thumbnails.(key) (string) . Possible values are :
    • “default” default thumbnail image. For videos it is 120px x 90px. For  a Channel it is 88px x 88px .
    • “medium” medium resolution thumbnail image. For videos it is 320px  x 180px. For  a Channel it is 240px x 240px .
    • “high” high resolution thumbnail image. For videos it is 480px  x 360. For  a Channel it is 800px x 800px.
    • “standard” better resolution than high thumbnail image. For videos it is 640px  x 480px. For  a Channel it is not available.
    • “maxres” highest resolution possible. or videos it is 1280px x 720. For  a Channel it is not available.
  • thumbnails.(key).url (string) url of thumbnail
  • thumbnails.(key).width (int) width in pixels.
  • thumbnails.(key).height (int) height in pixels.
  • title (string) title of Channel where this Activity is taking place.
  • type (string). Possible values are
    • “bulletin”
    • “channelItem”
    • “favorite”
    • “like”
    • “playlistItem”
    • “promotedItem”
    • “recommendation”
    • “social”
    • “subscription”
    • “upload”
  • groupId (string) The group ID associated with the activity. A group ID identifies user events that are associated with the same user and resource. For example, if a user rates a video and marks the same video as a favorite, the entries for those events would have the same group ID in the user’s activity feed.
  • upload (object) The upload object contains information about the uploaded video. This property is only present if the snippet.type is “upload”.
  • upload.videoId (string) The ID that YouTube uses to uniquely identify the uploaded video.
  • like (object) The like object contains information about a resource that received a positive (like) rating. This property is only present if the snippet.type is “like”.
  • like.resourceId.kind (string) The type of the API resource.
  • like.resourceId.videoId (string) The ID that YouTube uses to uniquely identify the video, if the rated resource is a video. This property is only present if the resourceId.kind is YouTube#video.
  • favorite (object) The favorite object contains information about a video that was marked as a favorite video. This property is only present if the snippet.type is favorite.
  • favorite.resourceId.kind (string) The type of the API resource
  • favorite.resourceId.videoId (string) The ID that YouTube uses to uniquely identify the favorite video. This property is only present if the resourceId.kind is YouTube#video.
  • subscription (object) The subscription object contains information about a channel that a user subscribed to. This property is only present if the snippet.type is “subscription”.
  • subscription.resourceId.kind (string) The type of the API resource.
  • subscription.resourceId.channelId (string) The ID that YouTube uses to uniquely identify the channel that the user subscribed to. This property is only present if the resourceId.kind is “YouTube#channel”.
  • playlistItem (object) The playlistItem object contains information about a new playlist item. This property is only present if the snippet.type is “playlistItem”.
  • playlistItem.resourceId.kind (string) The type of the API resource
  • playlistItem.resourceId.videoId (string) The ID that YouTube uses to uniquely identify the video that was added to the playlist. This property is only present if the resourceId.kind is “YouTube#video”.
  • playlistItem.playlistId (string) The value that YouTube uses to uniquely identify the playlist
  • playlistItem.playlistItemId (string) The value that YouTube uses to uniquely identify the item in the playlist.
  • recommendation (object) The recommendation object contains information about a recommended resource. This property is only present if the snippet.type is recommendation.
  • recommendation.resourceId.kind (string) The type of the API resource.
  • recommendation.resourceId.videoId (string) The ID that YouTube uses to uniquely identify the video, if the recommended resource is a video. This property is only present if the resourceId.kind is “YouTube#video”.
  • recommendation.resourceId.channelId (string) The ID that YouTube uses to uniquely identify the channel, if the recommended resource is a channel. This property is only present if the resourceId.kind is YouTube#channel.
  • recommendation.reason (string) Valid values are
    • “videoFavorited”
    • “videoLiked”
    • “videoWatched”
  • recommendation.seedResourceId (object) The seedResourceId object contains information about the resource that caused the recommendation.
  • recommendation.seedResourceId.kind (string) The type of the API resource.
  • recommendation.seedResourceId.videoId (string) The ID that YouTube uses to uniquely identify the video, if the recommendation was caused by a particular video. This property is only present if the seedResourceId.kind is “YouTube#video”.
  • recommendation.seedResourceId.channelId (string) The ID that YouTube uses to uniquely identify the channel, if the recommendation was caused by a particular channel. This property is only present if the seedResourceId.kind is “YouTube#channel”.
  • recommendation.seedResourceId.playlistId (string) The ID that YouTube uses to uniquely identify the playlist, if the recommendation was caused by a particular playlist. This property is only present if the seedResourceId.kind is “YouTube#playlist”.
  • bulletin (object) The bulletin object contains details about a channel bulletin post. This object is only present if the snippet.type is “bulletin”.
  • bulletin.resourceId.kind (string) The type of the API resource.
  • bulletin.resourceId.videoId (string) The ID that YouTube uses to uniquely identify the video featured in a bulletin post, if the post refers to a video. This property will only be present if the value of the bulletin.resourceId.kind property is “YouTube#video”
  • bulletin.resourceId.channelId (string) The ID that YouTube uses to uniquely identify the channel featured in a bulletin post, if the post refers to a channel. This property will only be present if the value of the bulletin.resourceId.kind property is “YouTube#channel”.
  • bulletin.resourceId.playlistId (string) The ID that YouTube uses to uniquely identify the playlist featured in a bulletin post, if the post refers to a playlist. This property will only be present if the value of the bulletin.resourceId.kind property is “YouTube#playlist”
  • social (object) The social object contains details about a social network post. This property is only present if the snippet.type is “social”.
  • social.type (string) Possible values are:
    • “facebook”
    • “googlePlus”
    • “twitter”
    • “unspecified”
  • social.resourceId.kind (string) The type of the API resource.
  • social.resourceId.videoId (string) The ID that YouTube uses to uniquely identify the video featured in a social network post, if the post refers to a video. This property will only be present if the value of the social.resourceId.kind property is “YouTube#video”.
  • social.resourceId.channelId (string) The ID that YouTube uses to uniquely identify the channel featured in a social network post, if the post refers to a channel. This property will only be present if the value of the social.resourceId.kind property is “YouTube#channel”.
  • social.resourceId.playlistId (string) The ID that YouTube uses to uniquely identify the playlist featured in a social network post, if the post refers to a playlist. This property will only be present if the value of the social.resourceId.kind property is “YouTube#playlist”.
  • social.author (string) The author of the social network post.
  • social.referenceUrl (string) The URL of the social network post.
  • social.imageUrl (string) An image of the post’s author.
  • channelItem (object) The channelItem object contains details about a resource that was added to a channel. This property is only present if the snippet.type is “channelItem”.
  • channelItem.resourceId (object) The resourceId object contains information that identifies the resource that was added to the channel.

 

Here is sample code which fetches activities for a Channel. This only requires the API Key

<?php
    error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
    set_time_limit(60 * 3);
    
    $g_YouTubeDataAPIKey = "****";
    $channelId = "UCIJ0lLcABPdYGp7pRMGccAQ";
    
   	 // make api request
   	 $url = "https://www.googleapis.com/YouTube/v3/activities?part=snippet,contentDetails,id&channelId=" .
   	 $channelId. "&maxResults=5&key=" . $g_YouTubeDataAPIKey;

   	 $curl = curl_init();
   	 curl_setopt_array($curl, array(
   				 CURLOPT_RETURNTRANSFER => 1,
   				 CURLOPT_URL => $url,
   				 CURLOPT_USERAGENT => 'YouTube API Tester',
   				 CURLOPT_SSL_VERIFYPEER => 1,
   				 CURLOPT_SSL_VERIFYHOST=> 0,
   				 CURLOPT_CAINFO => "../../cert/cacert.pem",
   				 CURLOPT_CAPATH => "../../cert/cacert.pem",
   				 CURLOPT_FOLLOWLOCATION => TRUE
   				 ));
   	 $resp = curl_exec($curl);

   	 curl_close($curl);

   	 
   	 if ($resp) {
   		 $json = json_decode($resp);
   		 if ($json) {
   			 echo("JSON decoded<br>");
   			 $total = $json->pageInfo->totalResults;

   			 $items = $json->items;
   		 }
   		 else
   			 exit("Error. could not parse JSON." . json_last_error_msg());

   	 
   		 foreach($items as $item) {
   			 $publishedAt = $item->snippet->publishedAt;
   			 $channelId = $item->snippet->channelId;
   			 $title = $item->snippet->title;

   			 $type = $item->snippet->type;
   			 
   			 $actityKind = "";
   			 $activityItemId = "";
   			 $activityInfo = "";

   			 if ($type == "bulletin") {
   				 $activityKind = $item->contentDetails->bulletin->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " . $item->contentDetails->bulletin->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " . $item->contentDetails->bulletin->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->social->resourceId->playlistId;
   				 }


   			 } else if ($type == "channelItem") {


   			 } else if ($type == "favorite") {
   				 $activityKind = $item->contentDetails->favorite->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->favorite->resourceId->videoId;
   				 }
   			 

   			 } else if ($type == "like") {
   				 $activityKind = $item->contentDetails->like->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->like->resourceId->videoId;
   				 }


   			 } else if ($type == "playlistItem") {
   				 $activityKind = $item->contentDetails->playlistItem->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->playlistItem->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " .$item->contentDetails->playlistItem->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->playlistItem->resourceId->playlistId;
   				 }


   			 } else if ($type == "promotedItem") {
   				 $activityKind = $item->contentDetails->promotedItem->resourceId->kind;


   			 } else if ($type == "recommendation") {
   				 $activityKind = $item->contentDetails->recommendation->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->recommendation->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " .$item->contentDetails->recommendation->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->recommendation->resourceId->playlistId;
   				 }
   			 
   				 $activityInfo .= "<br>Reason " .$item->contentDetails->recommendation->reason;
   				 $activityInfo .= "<br>Seed Resource Id " .$item->contentDetails->recommendation->seedResourceId;
   				 $activityInfo .= "<br>Seed Resource Kind " .$item->contentDetails->recommendation->seedResourceId->kind;
   				 
   				 $seedResourceKind =  $item->contentDetails->recommendation->seedResourceId->kind;
   			 	if ($seedResourceKind == "YouTube#video") {
   					 $activityInfo .= "<br> Seed Video id " .$item->contentDetails->recommendation->seedResourceId->videoId;
   				 }
   				 if ($seedResourceKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Seed Channel id " .$item->contentDetails->recommendation->seedResourceId->channelId;
   				 }
   				 if ($seedResourceKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Seed Playlist id " .$item->contentDetails->recommendation->seedResourceId->playlistId;
   				 }

    
   			 } else if ($type == "social") {
   				 $activityKind = $item->contentDetails->social->resourceId->kind;
   				 $activityInfo = $item->contentDetails->social->type;
   				 
   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->social->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " .$item->contentDetails->social->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->social->resourceId->playlistId;
   				 }
   				 $activityInfo .= "<br>Author=" .$item->contentDetails->social->author;
   				 $activityInfo .= "<br>URL=" .$item->contentDetails->social->referenceUrl;
   				 $activityInfo .= "<br>Author Image=" .$item->contentDetails->social->imageUrl;

   	 

   			 } else if ($type == "subscription") {

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->subscription->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " .$item->contentDetails->subscription->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->subscription->resourceId->playlistId;
   				 }


   			 } else if ($type == "upload") {
   				 $activityKind = $item->contentDetails->upload->resourceId->kind;
   				 
   				 $activityInfo .= "<br>Video id " .$item->contentDetails->upload->videoId;


   			 }

   			 echo("Date:" . $publishedAt . ", Channel Id:" . $channelId . " " . $title . "<br>");
   			 echo("Activity Type:" . $type . "<br>");
   			 echo("Kind: " . $activityKind . "<br>");
   			 echo($activityInfo);
   			 echo("<hr>");

   		 } // foreach
   	 } // if resp

   	 
    
?>

Here is the output:

JSON decoded
Date:2017-05-19T16:06:04.000Z, Channel Id:UCIJ0lLcABPdYGp7pRMGccAQ Fails of the Week: This Time, It's Personal (May 2017)
Activity Type:like
Kind: YouTube#video

Video id 8dlSd0xW8bQ
Date:2017-05-19T12:20:49.000Z, Channel Id:UCIJ0lLcABPdYGp7pRMGccAQ PEOPLE ARE AWESOME 2017 | BEST OF THE WEEK (Ep. 26)
Activity Type:upload
Kind:


Video id YQlmh5Egx5E
Date:2017-05-19T12:20:49.000Z, Channel Id:UCIJ0lLcABPdYGp7pRMGccAQ PEOPLE ARE AWESOME 2017 | BEST OF THE WEEK (Ep. 26)
Activity Type:bulletin
Kind: YouTube#video

Video id YQlmh5Egx5E
Date:2017-05-16T14:33:35.000Z, Channel Id:UCIJ0lLcABPdYGp7pRMGccAQ SPOTLIGHT: Natalie "Killface" Morgan - Muay Thai Fighter | PEOPLE ARE AWESOME 2017
Activity Type:upload
Kind:


Video id zXyFFCZG4HQ
Date:2017-05-12T12:04:12.000Z, Channel Id:UCIJ0lLcABPdYGp7pRMGccAQ PEOPLE ARE AWESOME 2017 | BEST OF THE WEEK (Ep. 25)
Activity Type:upload
Kind:

 

Below is code which fetches the Activities of a User. This requires OAuth and the API key.

<?php
    error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
    set_time_limit(60 * 3);
    session_start();

    $clientId = "****";
    $clientSecret = "***";
    $g_YouTubeDataAPIKey = "***";

  
    

    $_SESSION["code_id"] = $_SERVER["PHP_SELF"];
    
    if ($_SESSION["access_token"] == null || $_SESSION["access_token"] == "") {
   	 // check for oauth response
   	 header("Location: ../../init-login.php");
   	 exit;
    }
   	 
   	 
   	 $accessToken = $_SESSION["access_token"];
   	 
   	 // make api request
   	 $url = "https://www.googleapis.com/YouTube/v3/activities?part=snippet,contentDetails,id&mine=true&maxResults=5&key=" .
   			 $g_YouTubeDataAPIKey . "&access_token=" . $accessToken;

   	 $curl = curl_init();
   	 curl_setopt_array($curl, array(
   				 CURLOPT_RETURNTRANSFER => 1,
   				 CURLOPT_URL => $url,
   				 CURLOPT_USERAGENT => 'YouTube API Tester',
   				 CURLOPT_SSL_VERIFYPEER => 1,
   				 CURLOPT_SSL_VERIFYHOST=> 0,
   				 CURLOPT_CAINFO => "../../cert/cacert.pem",
   				 CURLOPT_CAPATH => "../../cert/cacert.pem",
   				 CURLOPT_FOLLOWLOCATION => TRUE
   				 ));
   	 $resp = curl_exec($curl);

   	 curl_close($curl);
   	 
    if ($resp) {
   		 $json = json_decode($resp);
   		 if ($json) {
   			 echo("JSON decoded<br>");
   			 $total = $json->pageInfo->totalResults;

   			 $items = $json->items;
   		 }
   		 else
   			 exit("Error. could not parse JSON." . json_last_error_msg());

   	 
   		 foreach($items as $item) {
   			 $publishedAt = $item->snippet->publishedAt;
   			 $channelId = $item->snippet->channelId;
   			 $title = $item->snippet->title;

   			 $type = $item->snippet->type;
   			 
   			 $actityKind = "";
   			 $activityItemId = "";
   			 $activityInfo = "";

   			 if ($type == "bulletin") {
   				 $activityKind = $item->contentDetails->bulletin->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " . $item->contentDetails->bulletin->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " . $item->contentDetails->bulletin->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->social->resourceId->playlistId;
   				 }


   			 } else if ($type == "channelItem") {


   			 } else if ($type == "favorite") {
   				 $activityKind = $item->contentDetails->favorite->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->favorite->resourceId->videoId;
   				 }
   			 

   			 } else if ($type == "like") {
   				 $activityKind = $item->contentDetails->like->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->like->resourceId->videoId;
   				 }


   			 } else if ($type == "playlistItem") {
   				 $activityKind = $item->contentDetails->playlistItem->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->playlistItem->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " .$item->contentDetails->playlistItem->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->playlistItem->resourceId->playlistId;
   				 }


   			 } else if ($type == "promotedItem") {
   				 $activityKind = $item->contentDetails->promotedItem->resourceId->kind;


   			 } else if ($type == "recommendation") {
   				 $activityKind = $item->contentDetails->recommendation->resourceId->kind;

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->recommendation->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " .$item->contentDetails->recommendation->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->recommendation->resourceId->playlistId;
   				 }
   			 
   				 $activityInfo .= "<br>Reason " .$item->contentDetails->recommendation->reason;
   				 $activityInfo .= "<br>Seed Resource Id " .$item->contentDetails->recommendation->seedResourceId;
   				 $activityInfo .= "<br>Seed Resource Kind " .$item->contentDetails->recommendation->seedResourceId->kind;
   				 
   				 $seedResourceKind =  $item->contentDetails->recommendation->seedResourceId->kind;
   			 	if ($seedResourceKind == "YouTube#video") {
   					 $activityInfo .= "<br> Seed Video id " .$item->contentDetails->recommendation->seedResourceId->videoId;
   				 }
   				 if ($seedResourceKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Seed Channel id " .$item->contentDetails->recommendation->seedResourceId->channelId;
   				 }
   				 if ($seedResourceKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Seed Playlist id " .$item->contentDetails->recommendation->seedResourceId->playlistId;
   				 }

    
   			 } else if ($type == "social") {
   				 $activityKind = $item->contentDetails->social->resourceId->kind;
   				 $activityInfo = $item->contentDetails->social->type;
   				 
   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->social->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " .$item->contentDetails->social->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->social->resourceId->playlistId;
   				 }
   				 $activityInfo .= "<br>Author=" .$item->contentDetails->social->author;
   				 $activityInfo .= "<br>URL=" .$item->contentDetails->social->referenceUrl;
   				 $activityInfo .= "<br>Author Image=" .$item->contentDetails->social->imageUrl;

   	 

   			 } else if ($type == "subscription") {

   				 if ($activityKind == "YouTube#video") {
   					 $activityInfo .= "<br>Video id " .$item->contentDetails->subscription->resourceId->videoId;
   				 }
   				 if ($activityKind == "YouTube#channel") {
   					 $activityInfo .= "<br>Channel id " .$item->contentDetails->subscription->resourceId->channelId;
   				 }
   				 if ($activityKind == "YouTube#playlist") {
   					 $activityInfo .= "<br>Playlist id " .$item->contentDetails->subscription->resourceId->playlistId;
   				 }


   			 } else if ($type == "upload") {
   				 $activityKind = $item->contentDetails->upload->resourceId->kind;
   				 
   				 $activityInfo .= "<br>Video id " .$item->contentDetails->upload->videoId;


   			 }

   			 echo("Date:" . $publishedAt . ", Channel Id:" . $channelId . " " . $title . "<br>");
   			 echo("Activity Type:" . $type . "<br>");
   			 echo("Kind: " . $activityKind . "<br>");
   			 echo($activityInfo);
   			 echo("<hr>");

   		 } // foreach
   	 } // if resp


   	 
    
?>

The API URL will have the parameter “mine=true” instead of “channelId=xx”. The output will be similar to that of Channel activities:

JSON decoded

Date:2017-05-18T05:18:16.000Z, Channel Id:UCnXmfpAZ1rLsg0Goh0bBHUA Peggy Rometo's Weekly Wake Up For 5-14-17
Activity Type:like
Kind: YouTube#video

Video id PTH0aANxYEM
Date:2017-05-15T08:31:41.000Z, Channel Id:UCnXmfpAZ1rLsg0Goh0bBHUA PISCES MAY 15,2017 WEEKLY HOROSCOPES BY MARIE MOORE
Activity Type:like
Kind: YouTube#video


Video id yddQLZLfVrg
Date:2017-05-14T04:34:21.000Z, Channel Id:UCnXmfpAZ1rLsg0Goh0bBHUA PISCES May 2017 Extended Monthly Tarot Reading | Intuitive Tarot by Nicholas
Activity Type:like
Kind: YouTube#video

Video id 0bVxFk1Ap0c
Date:2017-05-11T17:44:46.000Z, Channel Id:UCnXmfpAZ1rLsg0Goh0bBHUA 05 Mads langer - Overgir mig langsomt.
Activity Type:playlistItem
Kind: YouTube#video


Video id XnCYP8rGUqY
Date:2017-05-07T12:51:24.000Z, Channel Id:UCnXmfpAZ1rLsg0Goh0bBHUA Shayne Ward - No Promises
Activity Type:playlistItem
Kind: YouTube#video



Be the first to comment

Leave a Reply

Your email address will not be published.


*