如何使用 Objective C 中的 gdata 将视频上传到收藏夹/播放列表
我正在尝试将视频上传到我帐户中的收藏夹,但它显示无效的请求 Uri 和状态代码 =400
我不明白应该如何格式化我的请求
我的代码
NSURL *url = [NSURL URLWithString:
http://gdata.youtube.com/feeds/api/users/username/favorite];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"gdata.youtube.com" forKey:@"Host"];
[request setPostValue:@"application/atom+xml" forKey:@"Content-Type"];
[request setPostValue:@"CONTENT_LENGTH" forKey:@"Content-Length"];
[request setPostValue:@"" forKey:@"AuthSubToken"];
[request setPostValue:@"2" forKey:@"GData-Version"];
[request setPostValue:developer_key forKey:@"X-GData-Key"];
[request setPostValue:xml_data forKey:@"API_XML_Request"];
[request setDelegate:self];
[request setDidFailSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(gotTheResponse:)];
[[networkQueue go];
我有身份验证令牌和开发人员密钥,VIDEO_ID .但我不确定如何在post请求中传递xml数据:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<id>VIDEO_ID</id>
</entry>
NSString *xml_data = contains string form xml data
i am trying to upload a video to favorite in my account but it shows Invalid request Uri and status code =400
i dont understand how should i format my request
my code
NSURL *url = [NSURL URLWithString:
http://gdata.youtube.com/feeds/api/users/username/favorite];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"gdata.youtube.com" forKey:@"Host"];
[request setPostValue:@"application/atom+xml" forKey:@"Content-Type"];
[request setPostValue:@"CONTENT_LENGTH" forKey:@"Content-Length"];
[request setPostValue:@"" forKey:@"AuthSubToken"];
[request setPostValue:@"2" forKey:@"GData-Version"];
[request setPostValue:developer_key forKey:@"X-GData-Key"];
[request setPostValue:xml_data forKey:@"API_XML_Request"];
[request setDelegate:self];
[request setDidFailSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(gotTheResponse:)];
[[networkQueue go];
i have auth token and developer key, VIDEO_ID.but m not sure how to pass xml data in post request:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<id>VIDEO_ID</id>
</entry>
NSString *xml_data = contains xml data in string form
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该请求存在很多错误:它缺少 ClientLogin 或 OAuth 身份验证令牌、没有内容长度、XML 缺少命名空间,以及可能的其他问题。
您是否考虑过使用 GData Objective-C 客户端库?使用该库,添加收藏夹如下所示:
There is a lot wrong with the request: it lacks a ClientLogin or OAuth authentication token, there's no Content-Length, the XML lacks namespaces, and probably other issues.
Have you considered using the GData Objective-C client library? Using the library, adding a favorite looks like this: