Activity feeds list actions that a particular user or set of users has taken on the YouTube site. The API enables you to retrieve two types of activity feeds:
Activity feeds list the following user actions:
The following sections explain how to retrieve and process activity feeds:
An activity feed contains a series of <entry> tags, with each entry describing a particular event, like someone rating a video or creating a subscription. An event should appear in activity feeds within 30 minutes and may show up much sooner than that. Each feed entry contains the following elements that combine to identify the event:
Each entry contains an <author> tag, which encapsulates information about the user associated with the event. (Specifically, the <name> tag within the <author> tag identifies the user's username.)
Each entry contains a <category> tag for which the value of the scheme attribute is http://gdata.youtube.com/schemas/2007/userevents.cat. That tag's term attribute identifies the type of event that the entry describes. The following list identifies possible values for the term attribute. The list also identifies additional tags that will appear for each type to identify the specific event associated with the entry.
video_rated – A user rated a video. For this type of event, an entry will also contain the following tags:
video_shared – A user shared a video. For this type of event, an entry will also contain the following tag:
video_favorited – A user marked a video as a favorite. For this type of event, an entry will also contain the following tag:
video_commented – A user commented on a video. For this type of event, an entry will also contain the following tags:
rel attribute value of http://gdata.youtube.com/schemas/2007#comments contains a link to the feed URL for the comment that was added.rel attribute value of http://gdata.youtube.com/schemas/2007#video contains a link to the feed URL for the video to which the comment was added.video_uploaded – A user uploaded a video. For this type of event, an entry will also contain the following tag:
friend_added – A user added a friend. For this type of event, an entry will also contain the following tag:
user_subscription_added – A user added a subscription. For this type of event, an entry will also contain the following tag:
User activity feeds and friend activity feeds have the same structure, though the tags included within each feed entry varies slightly as described in the Retrieving an activity feed section.
The XML below shows a sample user activity feed for the following API request.
http://gdata.youtube.com/feeds/api/events?author=tayzonzay&v=2
The XML contains one entry, which identifies an instance of a video being marked as a favorite video.
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gml='http://www.opengis.net/gml' xmlns:georss='http://www.georss.org/georss' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:yt='http://gdata.youtube.com/schemas/2007' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/"D0EGSH47eCp7ImA9WxRVGEg."'> <id>tag:youtube.com,2008:events</id> <updated>2009-01-28T09:13:49.000Z</updated> <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#userEvent'/> <title>Activity of tayzonzay</title> <logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo> <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/events?v=2'/> <link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/events/batch?v=2'/> <link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/events?author=tayzonzay&start-index=...'/> <link rel='service' type='application/atomsvc+xml' href='http://gdata.youtube.com/feeds/api/events?alt=atom-service&v=2'/> <author> <name>YouTube</name> <uri>http://www.youtube.com/</uri> </author> <generator version='2.0' uri='http://gdata.youtube.com/'>YouTube data API</generator> <openSearch:totalResults>12</openSearch:totalResults> <openSearch:startIndex>1</openSearch:startIndex> <openSearch:itemsPerPage>25</openSearch:itemsPerPage> <entry gd:etag='W/"D0EGSH47eCp7ImA9WxRQQEg."'> <id>tag:youtube.com,2008:event:VGF5Wm9uZGF5MzEyaIl2MTMxOTcxMDk3NzQ5MzM%3D</id> <updated>2009-01-16T09:13:49.000Z</updated> <category scheme='http://gdata.youtube.com/schemas/2007/userevents.cat' term='video_favorited'/> <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#userEvent'/> <title>tayzonzay has favorited a video</title> <link rel='alternate' type='text/html' href='http://www.youtube.com'/> <link rel='http://gdata.youtube.com/schemas/2007#video' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/z3U0kuLH974?v=2'/> <link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/events/VGF5Wm9uZGF5MzEyaIl2MTMxOTcxMDk3NzQ5MzM%3D?v=2'/> <author> <name>tayzonzay</name> <uri>http://gdata.youtube.com/feeds/api/users/tayzonzay</uri> </author> <yt:videoid>z3U0kuLH974</yt:videoid> </entry> </feed>
User activity feeds list user events that occurred within the last 60 days. You can request a user activity feed for a single user or you can retrieve a single feed that lists actions from multiple users. You can also use the published-min and published-max parameters to specify that the API response should only contain events that occurred between specific times, such as events that occurred within the previous day or week. However, you cannot use the API to retrieve events that occurred more than 60 days before the time of your request.
Please see the Google Data APIs Protocol Reference for more information about these parameters.
The YouTube API provides two ways to retrieve a user activity feed. If you need to track updates for a large number of user activity feeds, consider using the Simple Update Protocol, which is supported if you use the first of the two retrieval methods described below.
To retrieve a single user's activity feed, send a request to the following URL. Replace the text username with the user's YouTube username.
http://gdata.youtube.com/feeds/api/users/username/events?v=2
You can also retrieve the user activity feed for the currently logged-in user by sending an HTTP GET request to the following URL. Note that for this request, you need to provide an authentication token in the Authorization HTTP request header, which enables YouTube to identify the user.
http://gdata.youtube.com/feeds/api/users/default/events?v=2
To retrieve a user activity feed that combines the actions of multiple users, send an HTTP request to the following URL. (You can also use this method to retrieve a user activity feed for a single user.) Your request must identify your developer key. In the request, set the author parameter value to a comma-separated list of up to 20 YouTube usernames. The API response will contain activities performed by any of those users.
http://gdata.youtube.com/feeds/api/events?author=usernames
Note that this feed URL does not support the Simple Update Protocol.
To retrieve a friend activity feed for the logged-in user's friends, send an HTTP request to the following URL. Note: For this request, you must provide an authentication token in the Authorization HTTP request header. This restriction ensures that a user can only retrieve the friend activity feed for her own friends.
http://gdata.youtube.com/feeds/api/users/default/friendsactivity
Friend activity feeds contain events that occurred within the last 14 days. Note that these feeds only contain events for contacts who are explicitly labeled as being in the user's Friends group, and they do not contain events for all of the user's contacts. As with user activity feeds, you can use the published-min and published-max parameters to specify that the API response should only contain events that occurred between specific times, such as events that occurred within the previous day or week. However, you cannot use the API to retrieve events that occurred more than 14 days before the time of your request. Please see the Google Data APIs Protocol Reference for more information about these parameters.
Even though an activity feed identifies the video or user associated with a particular event, the feed does not necessarily contain metadata about that video or user. For example, a feed entry that identifies a video_rated event contains the YouTube video ID for the video and the rating that the user gave to that video. However, the entry does not contain other metadata like the video's title, description or owner.
To retrieve additional information about the videos or users identified in an activity feed, you can submit a batch processing request. A batch processing request can retrieve up to 50 video entries or user profile entries.
To retrieve a list of video entries in a batch processing request, send an HTTP POST request to the following URL:
http://gdata.youtube.com/feeds/api/videos/batch
Each entry in the request will use the <id> tag to identify a video for which you want to retrieve additional information. Use the <yt:videoid> values from the activity feed entries to construct the <id> tag values for the batch processing request.
Activity feed:
<entry>
...
<category scheme='http://gdata.youtube.com/schemas/2007/userevents.cat'
term='video_favorited'/>
<yt:videoid>5EDAB37EA1823E58</yt:videoid>
</entry>
Batch processing request:
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/<yt:videoid></id>
</entry>
To retrieve a list of user profiles in a batch processing request, send an HTTP POST request to the following URL:
http://gdata.youtube.com/feeds/api/users/batch
Each entry in the request will use the <id> tag to identify a user whose profile you want to retrieve. Use the <yt:username> values from the activity feed entries to construct the <id> tag values for the batch processing request.
Activity feed:
<entry>
...
<category scheme='http://gdata.youtube.com/schemas/2007/userevents.cat'
term='user_subscription_added'/>
<yt:username>GoogleDevelopers</yt:username>
</entry>
Batch processing request:
<entry>
<id>http://gdata.youtube.com/feeds/api/users/<yt:username></id>
</entry>
Note: You cannot retrieve video entries and user profile entries in the same batch processing request, so you would need to submit separate requests (to different URLs) to retrieve video entries as well as user profile entries.
For example, the following batch processing request retrieves entries for three videos:
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:yt='http://gdata.youtube.com/schemas/2007'> <batch:operation type='query'/> <entry> <id>http://gdata.youtube.com/feeds/api/videos/ADos_xW4_J0</id> </entry> <entry> <id>http://gdata.youtube.com/feeds/api/videos/iIp7OnHXBlo</id> </entry> <entry> <id>http://gdata.youtube.com/feeds/api/videos/cBPzPdcMj1s</id> </entry> </feed>
Please see the batch processing documentation for additional information, including a sample response to a batch processing request.