Marking youtube videos as favorites

24 views
Skip to first unread message

Alvaro

unread,
Feb 19, 2009, 11:23:23 AM2/19/09
to Google Data APIs Objective-C Client Library Discussion
Hi,

Ive managed to get a feed of videos using the gdata api but I cant
find any method in the api for marking them as fauvorite or adding
them to a list. Assuming I am already logged and identified with a
developer key, how can I mark a video knowing its video Id?

I know how to do it sending a POST:

POST /feeds/api/users/default/favorites HTTP/1.1
Host: gdata.youtube.com
Content-Type: application/atom+xml
Content-Length: CONTENT_LENGTH
Authorization: AuthSub token=AUTHORIZATION_TOKEN
X-GData-Client: CLIENT_ID
X-GData-Key: key=DEVELOPER_KEY

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<id>VIDEO_ID</id>
</entry>


But, is there a way to do it through the API?

Thanks in advance,

Alvaro

Greg Robbins

unread,
Feb 19, 2009, 4:29:26 PM2/19/09
to gdata-objec...@googlegroups.com
Use GDataServiceGoogleYouTube's +youTubeURLForUserID:userFeedID: to make the URL for the favorites feed (kGDataYouTubeUserFeedIDFavorites), and -fetchYouTubeEntryByInsertingEntry: to post the entry to the feed.

Alvaro

unread,
Feb 19, 2009, 5:51:41 PM2/19/09
to gdata-objec...@googlegroups.com

Hi,

Thanks for aswering so fast!!

This is what Im trying:

-(void) addVideoToFeed:(NSString *)videoID {
    GDataServiceGoogleYouTube *service = [self youTubeService];
    GDataServiceTicket *ticket;
    NSURL *videoURL = [NSURL URLWithString: @"http://gdata.youtube.com/feeds/api/videos/VOO6Pac3XzE"];
    ticket = [service fetchYouTubeEntryWithURL:videoURL
                                               delegate:self
                                      didFinishSelector:@selector(insertVideoIntoFeed:finishedWithEntry:)
                                        didFailSelector:@selector(insertVideoIntoFeed:failedWithError:)
    ];   
       
}

- (void)insertVideoIntoFeed:(GDataServiceTicket *)ticket finishedWithEntry:(GDataEntryBase *)entry {
    NSLog(@"Lets mark it as favorie");
   
    GDataServiceGoogleYouTube *service = [self youTubeService];
    GDataServiceTicket *ticket2;
    NSURL *favFeedURL = [NSURL URLWithString: @"http://gdata.youtube.com/feeds/api/users/<USERID>/favorites"];
    ticket2 = [service fetchYouTubeEntryByInsertingEntry:entry
                                    forFeedURL:favFeedURL
                                      delegate:self
                             didFinishSelector:@selector(videoInsertedToFeed:finishedWithEntry:)
                               didFailSelector:@selector(videoInsertedToFeed:failedWithError:)
    ];   
}

The videoId is hardcoded for testing puposes and the youTubeService method defines the user-agent and the developer ey in addition to the username and the password:

// Returns a youTube Service
- (GDataServiceGoogleYouTube *)youTubeService {
    static GDataServiceGoogleYouTube *service = nil;
    if (!service) {
        service = [[GDataServiceGoogleYouTube alloc] init];
        [service setUserAgent:@"example-useragent-1.0"];
        [service setUserCredentialsWithUsername:@"username" password:@"password"];
        [service setYouTubeDeveloperKey:@"really long string developer key"];
    }
    return service;
}

But I get the following error:
Error: Error Domain=com.google.GDataServiceDomain Code=501 UserInfo=0x10cfe20 "Operation could not be completed. (com.google.GDataServiceDomain error 501.)"

Can you see what Im doing wrong???

Thanks again!!!

Alvaro

Greg Robbins

unread,
Feb 19, 2009, 5:58:18 PM2/19/09
to gdata-objec...@googlegroups.com
Is there more information about the failure in the error's userInfo dictionary?

Have you looked at an http log for additional information about the server error?

Is the error in response to the fetchYouTubeEntryByInsertingEntry: call?

Greg Robbins

unread,
Feb 19, 2009, 6:40:15 PM2/19/09
to gdata-objec...@googlegroups.com
This code works for me:

- (void)addToFavoritesEntry:(GDataEntryYouTubeVideo *)entry {

NSURL *favsFeedURL
  = [GDataServiceGoogleYouTube youTubeURLForUserID:kGDataServiceDefaultUser
  userFeedID:kGDataYouTubeUserFeedIDFavorites];


GDataServiceGoogleYouTube *service = [self youTubeService];
[service setYouTubeDeveloperKey:gDevKey];

GDataServiceTicket *ticket;
ticket = [service fetchYouTubeEntryByInsertingEntry:entry
  forFeedURL:favsFeedURL
  delegate:self
  didFinishSelector:@selector(insertFavoriteTicket:finishedWithEntry:)
  didFailSelector:@selector(insertFavoriteTicket:failedWithError:)];
}

Alvaro

unread,
Feb 20, 2009, 9:49:25 AM2/20/09
to gdata-objec...@googlegroups.com

Hi,

Im still getting the 501 error, could you please send me the full code or tell me how to get more info on the error's userInfo dictionary? how can I check the http log with xcode?

By the way, I cant use

NSURL *favsFeedURL
  = [GDataServiceGoogleYouTube youTubeURLForUserID:
kGDataServiceDefaultUser
  userFeedID:kGDataYouTubeUserFeedIDFavorites];

because xcode complains about kGDataServiceDefaultUser not being declared, So Im using:

NSURL *favsFeedURL
  = [GDataServiceGoogleYouTube youTubeURLForUserID:@"<username>"
  userFeedID:kGDataYouTubeUserFeedIDFavorites];

Is it relevant?

Thanks for your help!

Alvaro

Thomas Van Lenten

unread,
Feb 20, 2009, 10:03:41 AM2/20/09
to gdata-objec...@googlegroups.com
Are you using the latest sources or an older zip?

TVL

Greg Robbins

unread,
Feb 20, 2009, 2:33:50 PM2/20/09
to gdata-objec...@googlegroups.com
kGDataServiceDefaultUser is just the constant string @"default"

If you are not using the top-of-trunk sources from svn, you can define that constant yourself.

The userInfo dictionary for an error is available as [error userInfo]; you can log it with the %@ format specifier.

Message has been deleted

Greg Robbins

unread,
Feb 20, 2009, 8:14:06 PM2/20/09
to gdata-objec...@googlegroups.com
You can use the http logging described in GDataHTTPFetcherLogging.h to see the network traffic.

It's probably quicker just to examine the uploaded XML directly, with NSLog(@"%@", [entry XMLElement]);

Alvaro

unread,
Feb 20, 2009, 8:31:38 PM2/20/09
to gdata-objec...@googlegroups.com
The XMLElement looks nice, nothing strange ...I post it just in case you see something weird. Anayway, Ive tried with other videos and i get the same error ....

2009-02-21 02:28:34.504 app[6270:20b] GDataXMLElement 0x4B16240: {type:1 name:entry xml:"<entry xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns="http://www.w3.org/2005/Atom" gd:etag="W/&quot;D0UFRH47eCp7ImA9WxVXE00.&quot;"><link rel="alternate" href="http://www.youtube.com/watch?v=Y6p286FsBZE" type="text/html"/><link rel="http://gdata.youtube.com/schemas/2007#video.responses" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/responses" type="application/atom+xml"/><link rel="http://gdata.youtube.com/schemas/2007#video.ratings" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/ratings" type="application/atom+xml"/><link rel="http://gdata.youtube.com/schemas/2007#video.complaints" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/complaints" type="application/atom+xml"/><link rel="http://gdata.youtube.com/schemas/2007#video.related" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/related" type="application/atom+xml"/><link rel="http://gdata.youtube.com/schemas/2007#mobile" href="http://m.youtube.com/details?v=Y6p286FsBZE" type="text/html"/><link rel="self" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE" type="application/atom+xml"/><author><name>senorleche</name><uri>http://gdata.youtube.com/feeds/api/users/senorleche</uri><name>senorleche</name><uri>http://gdata.youtube.com/feeds/api/users/senorleche</uri></author><yt:statistics viewCount="39146" favoriteCount="35"/><content src="http://www.youtube.com/v/Y6p286FsBZE&amp;f=videos&amp;d=mk-cLrGcGWKf40EYPTAKVmD9LlbsOl3qUImVMV6ramM&amp;app=youtube_gdata" type="application/x-shockwave-flash"/><media:group><media:credit scheme="urn:youtube" role="uploader">senorleche</media:credit><media:keywords>backhandspring, back, handspring, flip</media:keywords><media:description type="plain">I can now do a back handspring</media:description><media:thumbnail width="130" url="http://i.ytimg.com/vi/Y6p286FsBZE/2.jpg" height="97" time="00:00:16.500"/><media:thumbnail width="130" url="http://i.ytimg.com/vi/Y6p286FsBZE/1.jpg" height="97" time="00:00:08.250"/><media:thumbnail width="130" url="http://i.ytimg.com/vi/Y6p286FsBZE/3.jpg" height="97" time="00:00:24.750"/><media:thumbnail width="480" url="http://i.ytimg.com/vi/Y6p286FsBZE/hqdefault.jpg" height="360"/><media:player url="http://www.youtube.com/watch?v=Y6p286FsBZE"/><media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat" label="People &amp; Blogs">People</media:category><media:title type="plain">BACKHANDSPRING!!!</media:title><yt:duration seconds="33"/><yt:videoid>Y6p286FsBZE</yt:videoid><media:content isDefault="true" url="http://www.youtube.com/v/Y6p286FsBZE&amp;f=videos&amp;d=mk-cLrGcGWKf40EYPTAKVmD9LlbsOl3qUImVMV6ramM&amp;app=youtube_gdata" type="application/x-shockwave-flash" expression="full" medium="video" duration="33" yt:format="5" format="5"/><media:content expression="full" url="rtsp://rtsp2.youtube.com/CkQLENy73wIaOwmRBWyh83aqYxMYDSANFEgGUgZ2aWRlb3NyIJpPnC6xnBlin-NBGD0wClZg_S5W7Dpd6lCJlTFeq2pjDA==/0/0/0/video.3gp" type="video/3gpp" duration="33" medium="video" yt:format="1" format="1"/><media:content expression="full" url="rtsp://rtsp2.youtube.com/CkQLENy73wIaOwmRBWyh83aqYxMYESARFEgGUgZ2aWRlb3NyIJpPnC6xnBlin-NBGD0wClZg_S5W7Dpd6lCJlTFeq2pjDA==/0/0/0/video.3gp" type="video/3gpp" duration="33" medium="video" yt:format="6" format="6"/><yt:uploaded>2006-07-18T07:50:21.000Z</yt:uploaded><media:title type="plain">BACKHANDSPRING!!!</media:title><media:description type="plain">I can now do a back handspring</media:description><media:keywords>backhandspring, back, handspring, flip</media:keywords><yt:duration seconds="33"/><yt:videoid>Y6p286FsBZE</yt:videoid><yt:uploaded>2006-07-18T07:50:21.000Z</yt:uploaded><media:player url="http://www.youtube.com/watch?v=Y6p286FsBZE"/><media:category label="People &amp; Blogs" scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category><media:credit role="uploader" scheme="urn:youtube">senorleche</media:credit><media:content url="http://www.youtube.com/v/Y6p286FsBZE&amp;f=videos&amp;d=mk-cLrGcGWKf40EYPTAKVmD9LlbsOl3qUImVMV6ramM&amp;app=youtube_gdata" type="application/x-shockwave-flash" medium="video" isDefault="true" expression="full" duration="33" yt:format="5"/><media:content url="rtsp://rtsp2.youtube.com/CkQLENy73wIaOwmRBWyh83aqYxMYDSANFEgGUgZ2aWRlb3NyIJpPnC6xnBlin-NBGD0wClZg_S5W7Dpd6lCJlTFeq2pjDA==/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="33" yt:format="1"/><media:content url="rtsp://rtsp2.youtube.com/CkQLENy73wIaOwmRBWyh83aqYxMYESARFEgGUgZ2aWRlb3NyIJpPnC6xnBlin-NBGD0wClZg_S5W7Dpd6lCJlTFeq2pjDA==/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="33" yt:format="6"/><media:thumbnail url="http://i.ytimg.com/vi/Y6p286FsBZE/2.jpg" height="97" width="130" time="00:00:16.500"/><media:thumbnail url="http://i.ytimg.com/vi/Y6p286FsBZE/1.jpg" height="97" width="130" time="00:00:08.250"/><media:thumbnail url="http://i.ytimg.com/vi/Y6p286FsBZE/3.jpg" height="97" width="130" time="00:00:24.750"/><media:thumbnail url="http://i.ytimg.com/vi/Y6p286FsBZE/hqdefault.jpg" height="360" width="480"/></media:group><id>tag:youtube.com,2008:video:Y6p286FsBZE</id><category term="People" label="People &amp; Blogs" scheme="http://gdata.youtube.com/schemas/2007/categories.cat"/><category term="http://gdata.youtube.com/schemas/2007#video" scheme="http://schemas.google.com/g/2005#kind"/><category term="backhandspring" scheme="http://gdata.youtube.com/schemas/2007/keywords.cat"/><category term="back" scheme="http://gdata.youtube.com/schemas/2007/keywords.cat"/><category term="flip" scheme="http://gdata.youtube.com/schemas/2007/keywords.cat"/><category term="handspring" scheme="http://gdata.youtube.com/schemas/2007/keywords.cat"/><updated>2009-02-10T22:33:35.000Z</updated><published>2006-07-18T07:50:21.000Z</published><gd:rating average="3.96" max="5" numRaters="72" min="1"/><title>BACKHANDSPRING!!!</title><gd:comments><gd:feedLink href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/comments" countHint="114"/><gd:feedLink href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/comments" countHint="114"/></gd:comments><id>tag:youtube.com,2008:video:Y6p286FsBZE</id><published>2006-07-18T07:50:21.000Z</published><updated>2009-02-10T22:33:35.000Z</updated><category scheme="http://gdata.youtube.com/schemas/2007/categories.cat" term="People" label="People &amp; Blogs"/><category scheme="http://schemas.google.com/g/2005#kind" term="http://gdata.youtube.com/schemas/2007#video"/><category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="backhandspring"/><category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="back"/><category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="flip"/><category scheme="http://gdata.youtube.com/schemas/2007/keywords.cat" term="handspring"/><title>BACKHANDSPRING!!!</title><content type="application/x-shockwave-flash" src="http://www.youtube.com/v/Y6p286FsBZE&amp;f=videos&amp;d=mk-cLrGcGWKf40EYPTAKVmD9LlbsOl3qUImVMV6ramM&amp;app=youtube_gdata"/><link rel="alternate" type="text/html" href="http://www.youtube.com/watch?v=Y6p286FsBZE"/><link rel="http://gdata.youtube.com/schemas/2007#video.responses" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/responses"/><link rel="http://gdata.youtube.com/schemas/2007#video.ratings" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/ratings"/><link rel="http://gdata.youtube.com/schemas/2007#video.complaints" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/complaints"/><link rel="http://gdata.youtube.com/schemas/2007#video.related" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/related"/><link rel="http://gdata.youtube.com/schemas/2007#mobile" type="text/html" href="http://m.youtube.com/details?v=Y6p286FsBZE"/><link rel="self" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE"/><author><name>senorleche</name><uri>http://gdata.youtube.com/feeds/api/users/senorleche</uri></author><media:group><media:title type="plain">BACKHANDSPRING!!!</media:title><media:description type="plain">I can now do a back handspring</media:description><media:keywords>backhandspring, back, handspring, flip</media:keywords><yt:duration seconds="33"/><yt:videoid>Y6p286FsBZE</yt:videoid><yt:uploaded>2006-07-18T07:50:21.000Z</yt:uploaded><media:player url="http://www.youtube.com/watch?v=Y6p286FsBZE"/><media:category label="People &amp; Blogs" scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category><media:credit role="uploader" scheme="urn:youtube">senorleche</media:credit><media:content url="http://www.youtube.com/v/Y6p286FsBZE&amp;f=videos&amp;d=mk-cLrGcGWKf40EYPTAKVmD9LlbsOl3qUImVMV6ramM&amp;app=youtube_gdata" type="application/x-shockwave-flash" medium="video" isDefault="true" expression="full" duration="33" yt:format="5"/><media:content url="rtsp://rtsp2.youtube.com/CkQLENy73wIaOwmRBWyh83aqYxMYDSANFEgGUgZ2aWRlb3NyIJpPnC6xnBlin-NBGD0wClZg_S5W7Dpd6lCJlTFeq2pjDA==/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="33" yt:format="1"/><media:content url="rtsp://rtsp2.youtube.com/CkQLENy73wIaOwmRBWyh83aqYxMYESARFEgGUgZ2aWRlb3NyIJpPnC6xnBlin-NBGD0wClZg_S5W7Dpd6lCJlTFeq2pjDA==/0/0/0/video.3gp" type="video/3gpp" medium="video" expression="full" duration="33" yt:format="6"/><media:thumbnail url="http://i.ytimg.com/vi/Y6p286FsBZE/2.jpg" height="97" width="130" time="00:00:16.500"/><media:thumbnail url="http://i.ytimg.com/vi/Y6p286FsBZE/1.jpg" height="97" width="130" time="00:00:08.250"/><media:thumbnail url="http://i.ytimg.com/vi/Y6p286FsBZE/3.jpg" height="97" width="130" time="00:00:24.750"/><media:thumbnail url="http://i.ytimg.com/vi/Y6p286FsBZE/hqdefault.jpg" height="360" width="480"/></media:group><yt:statistics viewCount="39146" favoriteCount="35"/><gd:rating min="1" max="5" numRaters="72" average="3.96"/><gd:comments><gd:feedLink href="http://gdata.youtube.com/feeds/api/videos/Y6p286FsBZE/comments" countHint="114"/></gd:comments></entry>"}


THANKS!

Greg Robbins

unread,
Feb 20, 2009, 8:57:00 PM2/20/09
to gdata-objec...@googlegroups.com
That entry has two elements equal to <media:title type="plain">BACKHANDSPRING!!!</media:title> and perhaps other duplicates.

You can look at the http log to match the column number reported in the server error to the uploaded XML.

Greg Robbins

unread,
Feb 20, 2009, 11:48:21 PM2/20/09
to gdata-objec...@googlegroups.com
alexkac pointed out that the duplicate name was due to a bug I recently checked in to the top-of-trunk version of the library sources. It's now fixed; just do an svn update on your source tree.

Alvaro

unread,
Feb 21, 2009, 5:43:28 AM2/21/09
to gdata-objec...@googlegroups.com
Thank you all very much, I did the svn update and now its working!!!!
Reply all
Reply to author
Forward
0 new messages