I have an iOS app that gets all the videos from a user through gdata and YouTube API. My problem comes with private videos, I need to make it so that it makes a private video public when the video is selected.
For some reason whenever I try to make the video public, I cannot edit it because the editLink
of an entry returned by YouTube API is empty.
Here's my code someone can tell me what I'm doing wrong or what I can do to make the change:
GDataEntryBase *entry = [[feed entries] objectAtIndex:selectedRow];
[[(GDataEntryYouTubeVideo *)entry mediaGroup] setIsPrivate:NO];
//GDataEntryYouTubeUpload *uploadEntry =
//[GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
//fileHandle:nil MIMEType:@"video/mp4" slug:[[entry title]
//stringValue]];
GDataServiceTicket *ticket;
GDataServiceGoogleYouTube *service = [self youTubeService];
NSString *str = [entry canEdit] ? @"YES" : @"NO";
NSLog(@"Can edit %@", str);
NSLog(@"Edit URL %@", [[entry editLink] URL] );
// NSURL *url = [GDataServiceGoogleYouTube
//youTubeUploadURLForUserID:kGDataServiceDefaultUser];
ticket = [service fetchEntryByUpdatingEntry:entry
forEntryURL:[[entry editLink] URL] delegate:self
didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];
// ticket = [service fetchEntryByUpdatingEntry:entry
//delegate:self didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];
NSLog(@"Ticket = %@", ticket);
}
}
- (void)uploadTicket:(GDataServiceTicket *)ticket
finishedWithEntry:(GDataEntryYouTubeVideo *)videoEntry error:(NSError
*)error {
NSLog(@"Finished...");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload
failed" message:[NSString stringWithFormat:@"Upload failed: %@",
error] delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:nil, nil];
if (error != nil) {
NSLog(@"Errors: %@", error);
[alert show];
} else {
NSLog(@"NO ERRORS :))");
}
}
I included developer key in the request/response shown below and received the editLink in the response. You will have to relate the protocol using the oauth playground to your client-side language.
https://groups.google.com/group/youtube-api-gdata/browse_thread/thread/346eb7c8bdd6c3ae
Did you authenticate your requests?
Did you specify v=2?
Did you include the developer key in the query?
If your authenticated and using v=2 in the query string then you should get the edit link.
Learn the dev tools at https://code.google.com/oauthplayground/ where i made the following request specifying partial gdata fields that would contain just the link[@rel="edit"] tag :
GET /feeds/api/users/default/uploads/7dtC4kS3x08?v=2&fields=link%5B%40rel%3D%22edit%22%5D&alt=json&key=${YT-devKeyValue} HTTP/1.1
Host: gdata.youtube.com
Authorization: OAuth ya29.AHES6ZSqIlhsyFfbzZ7x-PTVR1JiTj1PjPvBbfq7RtKnaJk
Response includes editlink at the bottom - you should use the value of the attribute=href when you POST your update to the api:
{
"version":"1.0",
"encoding":"UTF-8",
"entry":{
"xmlns":"http://www.w3.org/2005/Atom",
"xmlns$yt":"http://gdata.youtube.com/schemas/2007",
"link":[
{
"rel":"edit",
"type":"application/atom+xml",
"href":"https://gdata.youtube.com/feeds/api/users/rowntreerob/uploads/7dtC4kS3x08?v=2"
}
]
}
}