【问题标题】:youtube api v3 comments to videos for iOSyoutube api v3 对 iOS 视频的评论
【发布时间】:2013-04-22 20:17:03
【问题描述】:

我正在 iPhone 上开发一个只查看我的频道的应用程序,我需要在视频上制作一个 cmets。我使用了 youtube-api v2.0,它总是以错误响应。 我在 V3.0 中搜索了一个 cmets 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> 

【问题讨论】:

  • API v3 中不支持 cmets,我们没有任何关于是否/何时添加它们的信息。您应该可以使用 v2,但您没有向我们提供足够的信息来告诉您为什么它不起作用。请编辑您的问题,在您返回的 HTTP 响应正文中包含错误。
  • 仅使用xcode 来解决有关 IDE 本身的问题。谢谢!
  • @Jeff Posnick :我已经编辑了响应,如图所示

标签: iphone ios objective-c youtube-api


【解决方案1】:

XML 字符串的最后一部分为&lt;/entry/&gt;,它不是有效的结束标记。你想要&lt;/entry&gt;

【讨论】:

    猜你喜欢
    • 2016-09-01
    • 2015-03-03
    • 2012-12-17
    • 2012-11-07
    • 2013-11-21
    • 2017-10-04
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多