首页 文章

YouTube-Api评论视频

提问于
浏览
0

我试图通过youtube api评论youtube视频 . 我必须将一些XML发送到他们的服务器,但是当我这样做时,我没有回复任何内容,也没有对视频进行评论 .

继承人link to the api documentation

POST / feeds / api / videos / VIDEO_ID / comments HTTP / 1.1主机:gdata.youtube.com Content-Type:application / atom xml Content-Length:CONTENT_LENGTH授权:Bearer ACCESS_TOKEN GData-Version:2 X-GData-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>

我非常感谢你的帮助,因为我已经坚持了好几天 . 谢谢!

这是我的代码: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];

1 回答

  • 0

    每当您发出HTTP请求时,YouTube API都会 always 发送HTTP响应 . 即使你发出完全无效的HTTP请求,你也会得到任何回复 . 如果你're really not, then my guess is that you'实际上没有完成你的HTTP请求 - 也许它's never making it to the API servers due to some network problems, or perhaps you'没有正确计算 CONTENT_LENGTH (假设你试图手动计算它) .

    另外,如果你还没有,我建议使用GData Objective-C client library .

相关问题