youtube api v3对iOS视频的评论

时间:2013-04-22 20:17:03

标签: iphone ios objective-c youtube-api

我正在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> 

1 个答案:

答案 0 :(得分:1)

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