2013-04-22 76 views
0

我正在iPhone上開發一款應用程序,僅查看我的頻道,我需要對視頻進行評論。我用過youtube-api v2.0,它總是以錯誤迴應。 我在V3.0中搜索了一個評論API,但沒有任何結果。 任何人都可以查看下面的代碼,我可能執行錯誤,否則請告訴我如何開發它。youtube api v3針對iOS的視頻評論

-(IBAction)commentClicked:(id)sender{ 
   NSString *[email protected]"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> 
+0

API不支持第3版中的評論,我們也沒有任何關於它們是否將被添加的信息。你應該可以使用v2,但是你沒有提供足夠的信息來告訴你它爲什麼不起作用。請編輯您的問題,將錯誤包含在您回覆的HTTP響應正文中。 – 2013-04-22 20:46:06

+0

只有使用[tag:xcode]才能瞭解關於IDE本身的問題。謝謝! – Undo 2013-04-22 20:54:55

+0

@Jeff Posnick:我編輯瞭如圖所示的回覆 – 2013-04-22 21:07:25

回答

1

你的XML字符串的最後一部分內容</entry/>,這不是一個有效的關閉標籤。你想要</entry>

+0

thnx @jeff posnick – 2013-04-22 21:30:19