Api Comment on videos

I'm trying to comment on a youtube video via the youtube api. I have to send some XML to their server, but when i do it gives me nothing back, neither comments it on the video.

Heres the link to the api documentation!

POST /feeds/api/videos/VIDEO_ID/comments HTTP/1.1

Host: gdata.youtube.com

Content-Type: application/atom+xml

Content-Length: CONTENT_LENGTH

Authorization: Bearer ACCESS_TOKEN

GData-Version: 2

X-GData-Key: key=DEVELOPER_KEY

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

I really appreciate all your help, because I'm stuck on this for days. Thanks!

Here is my code: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *requestString = [NSString stringWithFormat:@"<?xml version="1.0" encoding="UTF-8"?><entry xmlns="http://www.w3.org/2005/Atom"xmlns:yt="http://gdata.youtube.com/schemas/2007"><content>%@</content></entry>", [textField text]];

NSData *postData = [requestString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setURL:[NSURL URLWithString:@"https://gdata.youtube.com/feeds/api/videos/4NE7Nmmt0R4/comments"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/atom+xml" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"key=%@", [defaults objectForKey:@"accessToken"]] forHTTPHeaderField:@"Authorization"];
[request setValue:@"key=AI39si4apF3QyQkXbH_C5IHIClkyP2mio2QJ3JBUUpvPbO2rhch7tpYjMavZgt5QzGaGrHBfom5mNpoUq_ZLRPPa35KO21O9Pw" forHTTPHeaderField:@"X-GData-Key"];
[request setValue:@"2" forHTTPHeaderField:@"GData-Version"];

[request setHTTPBody:postData];

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

[conn start];

The YouTube API will always send an HTTP response whenever you make an HTTP request. Even if you make a completely invalid HTTP request, you'll get back an HTTP error response. Please double-check to see if you're getting any response back at all. If you're really not, then my guess is that you're not actually completing your HTTP request—perhaps it's never making it to the API servers due to some network problems, or perhaps you're not calculating CONTENT_LENGTH correctly (assuming you're attempting to calculate it by hand).

Also, I'd recommend using the GData Objective-C client library if you're not already.

链接地址: http://www.djcxy.com/p/48870.html

上一篇: YouTube API设置播放列表位置

下一篇: Api评论视频