首页 文章

Youtube API对视频发表评论

提问于
浏览
1

我正在使用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);

现在我正在尝试使用HTTP Post请求在android上发布评论,但无法在android中创建POST URL

https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=ffL25JVXbo0&key=AIzaSyAQSINj5dtoLdSNJA3cc6dkziFC2zbbEuk&snippet.topLevelComment.snippet.textOriginal=my%20comment

1 回答

  • 0

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

    enter image description here

    尝试使用documentationTry it part 并检查视频中是否有评论 .

    请注意,将下拉按钮更改为 Newest first 以查看检查视频中的评论的最新评论 .

    enter image description here

    此外,CommentThreads: insert的文档中指出,您必须为这些属性指定值:

    • snippet.channelId

    • snippet.topLevelComment.snippet.textOriginal

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

相关问题