Android Youtube API在视频上发表评论

Android Youtube API在视频上发表评论,android,ios,youtube,youtube-api,youtube-data-api,Android,Ios,Youtube,Youtube Api,Youtube Data Api,我正在使用Youtube API显示视频,现在我需要在Youtube视频上发表评论。下面是正在运行的iOS代码 NSString *urlStr = @"http://gdata.youtube.com/feeds/mobile/videos/W_KEuea8eIw/comments"; NSURL *url = [NSURL URLWithString:urlStr]; NSMutableURLRequest *request = [NSMutableURLRequest requestWit

我正在使用Youtube API显示视频,现在我需要在Youtube视频上发表评论。下面是正在运行的iOS代码

NSString *urlStr = @"http://gdata.youtube.com/feeds/mobile/videos/W_KEuea8eIw/comments";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *xmlString = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"xmlns:yt=\"http://gdata.youtube.com/schemas/2007;\"><content>This is a crazy video</content></entry/>";
[request setHTTPMethod: @"POST" ];
[request setValue:@"application/atom+xml" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[xmlString dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:@"2.1" forHTTPHeaderField:@"GData-Version"];
[request setValue:[NSString stringWithFormat:@"key=%@",kSampleDeveloperKey] forHTTPHeaderField:@"X-GData-Key"];
[request setValue:[NSString stringWithFormat:@"Bearer %@",self.auth.accessToken] forHTTPHeaderField:@"Authorization"];
NSURLResponse *response;
NSError *err;
NSData*returnData=[ NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
NSLog(@"responseData: %@", content);

好吧,我试过了,我成功地在你提供的视频中发表了评论

试着使用这篇文章的试用部分,检查视频中是否有你的评论

请注意,将下拉按钮更改为最新优先,以便在检查视频中的评论时查看最新评论

此外,的文档中还规定,您必须为这些属性指定一个值:

  • snippet.channelId

  • snippet.topLevelComment.snippet.textOriginal


因此,请尝试在您的请求中也包含channelId。

好吧,我尝试了,并且成功地在您提供的视频中发布了一条评论

试着使用这篇文章的试用部分,检查视频中是否有你的评论

请注意,将下拉按钮更改为最新优先,以便在检查视频中的评论时查看最新评论

此外,的文档中还规定,您必须为这些属性指定一个值:

  • snippet.channelId

  • snippet.topLevelComment.snippet.textOriginal


因此,请尝试在您的请求中也包含channelId。

您有要传递的请求片段吗?我试过这个方法。转到
https://www.hurl.it/
然后选择POST选项。内部URL
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&key=MyKey
和正文
{0:{name:“snippet.channelId”,“UCfwHP1M0AFSPqTdjzXhV0Zg:”},“1:{name:“snippet.videoId”,“PA6oX7YPLWc:”},“2:{”name:“snippet.topLevelComment.snippet.textOriginal”,“谢谢你的配方”:“}”
但这给了我401错误。我没有选择任何身份验证方法。我的假设是,当我们使用Api密钥时,我们不需要任何身份验证。您有要传递的请求片段吗?我试过这个方法。转到
https://www.hurl.it/
然后选择POST选项。内部URL
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&key=MyKey
和正文
{0:{name:“snippet.channelId”,“UCfwHP1M0AFSPqTdjzXhV0Zg:”},“1:{name:“snippet.videoId”,“PA6oX7YPLWc:”},“2:{”name:“snippet.topLevelComment.snippet.textOriginal”,“谢谢你的配方”:“}”
但这给了我401错误。我没有选择任何身份验证方法。我的假设是,当我们使用Api密钥时,我们不需要任何身份验证。有解决方案吗?有解决方案吗?
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=ffL25JVXbo0&key=AIzaSyAQSINj5dtoLdSNJA3cc6dkziFC2zbbEuk&snippet.topLevelComment.snippet.textOriginal=my%20comment