我有一个iOS应用,可以通过gdata和YouTube API获取用户的所有视频。我的问题来自私人视频,我需要制作它,以便在选择视频时公开私人视频。
出于某种原因,每当我尝试将视频公开时,我都无法对其进行编辑,因为YouTube API返回的条目的editLink
为空。
这是我的代码,有人可以告诉我我做错了什么或我可以做些什么来改变:
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 :))");
}
}
答案 0 :(得分:0)
我在下面显示的请求/响应中包含了开发人员密钥,并在响应中收到了editLink。您必须使用oauth playground将协议与客户端语言相关联。
https://groups.google.com/group/youtube-api-gdata/browse_thread/thread/346eb7c8bdd6c3ae
您是否验证了您的请求?
您是否指定了v = 2?
您是否在查询中包含了开发人员密钥?
如果您在查询字符串中进行了身份验证并使用v = 2,那么您应该获得编辑链接。
在https://code.google.com/oauthplayground/了解开发工具,我发出以下请求,指定仅包含链接[@ rel =“edit”] 标记的部分gdata字段:
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
响应包括底部的editlink - 当你将更新发布到api时,你应该使用attribute = href的值:
{
"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"
}
]
}
}