youtube api v3对iOS视频的评论



我正在开发一个iPhone上的应用程序,只查看我的频道,我需要对视频发表评论。我使用过youtube-api v2.0,它总是响应一个错误。我在谷歌上搜索了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);
}

这里是responsedata

 <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>

相关内容

  • 没有找到相关文章