0

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

这是响应数据

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

1 回答 1

1

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

于 2013-04-22T21:21:06.673 回答