gpt4 book ai didi

objective-c - YouTube Objective-C HTTP POST请求评论

转载 作者:行者123 更新时间:2023-12-03 05:42:51 25 4
gpt4 key购买 nike

我正在尝试通过我的应用向YouTube视频添加评论,但显然不起作用。然后我去了Api v2网站,看到了:


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



但这并没有给我任何返回,也没有发表评论。
那么,我必须将发帖请求发送到哪里?我必须写些什么?

到目前为止,这是我的代码:
SBJsonParser *parser = [[SBJsonParser alloc] init];

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/FejWBVt7jtk/comments"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/atom+xml" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"Bearer %@", [defaults objectForKey:@"accessToken"]] forHTTPHeaderField:@"Authorization"];
[request setValue:@"key=DEVELOPER KEY" forHTTPHeaderField:@"X-GData-Key"];

[request setHTTPBody:postData];

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSDictionary *dict = [parser objectWithString:content];
NSLog(@"%@", dict);

谢谢!

最佳答案

不完全确定您的问题是什么,但是使用Google's Objective-C library可能会更好。

关于objective-c - YouTube Objective-C HTTP POST请求评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13435192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com