iphone - YouTube api v3 对 iOS 视频的评论

标签 iphone ios objective-c youtube-api

我正在 iPhone 上开发一个应用程序,该应用程序仅查看我的 channel ,并且我需要对视频发表评论。我使用过 youtube-api v2.0,它总是响应错误。 我在 Google 上搜索了 V3.0 中的评论 API,但没有结果。 任何人都可以查看以下代码,我可能实现了一些错误,否则请告诉我如何开发它。

    -(IBAction)commentClicked:(id)sender{
    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);
}

这是响应数据

 <errors xmlns='http://schemas.google.com/g/2005'>
    <error>
<domain>GData</domain>
<code>ParseException</code>
<internalReason>Element type "entry" must be followed by either attribute specifications, "&gt;" or "/&gt;".</internalReason>
</error>
</errors> 

最佳答案

XML 字符串的最后一部分为 </entry/> ,这不是有效的结束标记。您想要</entry> .

关于iphone - YouTube api v3 对 iOS 视频的评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16155947/

相关文章:

iphone - 如何将 View 添加到页面控件

iphone - 在 iPhone 中集成 sqlite

iOS-如何使表格 View 中的每个单元格变大?

ios - MPMoviePlayerViewController 在 iOS 10 Xcode 8 中崩溃应用程序

iphone - UICollectionView奇数单元格留空

ios - 在ipad/iphone app中使用众所周知的免费内存代码是否合法?

iphone - 我可以知道ipad是否重新启动吗?

objective-c - 让 NSRunLoop 等待设置标志的最佳方法?

ios - 如何在 iOS 13 中使用 Objective-c 中的 BGTask(后台获取)

objective-c - '-(bool)validateToolbarItem:(NSToolbarItem *)theItem' 的类型冲突