我是沃金在YouTube上上傳可恢復: https://developers.google.com/youtube/2.0/developers_guide_protocol_resumable_uploads#Sending_a_Resumable_Upload_API_Request如何使用如下的ASIHttpRequest創建請求?
我沒有創建像下面用ASIHttpRequest的請求。 如何使它工作?謝謝!任何幫助將不勝感激!
(1)
POST /resumable/feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: Bearer ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Content-Length: 0
Slug: my_file.mp4
(2)
POST /resumable/feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: Bearer ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Content-Length: 1941255
Slug: my_file.mp4
Content-Type: application/atom+xml; charset=UTF-8
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Bad Wedding Toast</media:title>
<media:description type="plain">
I gave a bad toast at my friend's wedding.
</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
</media:category>
<media:keywords>toast, wedding</media:keywords>
</media:group>
</entry>
這是我的(2),請求完成沒有錯誤,但該responseData是empty.I代碼不知道爲什麼!
NSURL *uploadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads"]];
ASIFormDataRequest *theRequest = [ASIFormDataRequest requestWithURL:uploadUrl];
NSString *xmlStr = [NSString stringWithFormat:@"<?xml version=\"1.0\"?>\n"
@"<entry xmlns=\"http://www.w3.org/2005/Atom\"\n"
@"xmlns:media=\"http://search.yahoo.com/mrss/\"\n"
@"xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\n"
@"<media:group>\n"
//Title
@"<media:title type=\"plain\">%@</media:title>\n"
//Description
@"<media:description type=\"plain\">\n"
@"%@\n"
@"</media:description>\n"
//Category
@"<media:category\n"
@"scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">Entertainment\n"
@"</media:category>\n"
//Keywords
@"<media:keywords>Camera,PowerCam</media:keywords>\n"
@"</media:group>\n"
@"</entry>\n", @"PowerCam.mov",@"description" ];
[theRequest setTimeOutSeconds:60];
[theRequest addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"Bearer %@",_oauth.accessToken]];
[theRequest addRequestHeader:@"GData-Version" value:@"2"];
[theRequest addRequestHeader:@"X-GData-Key" value:[NSString stringWithFormat:@"key=%@", YouTuDevkey]];
[theRequest addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d",xmlStr.length]];
[theRequest addRequestHeader:@"Slug" value:@"PowerCam.mov"];
[theRequest addRequestHeader:@"Content-Type" value:@"application/atom+xml; charset=UTF-8"];
[theRequest appendPostData:[xmlStr dataUsingEncoding:NSUTF8StringEncoding]];
[theRequest setUploadProgressDelegate:self];
theRequest.delegate = self;
theRequest.tag = eWSKYouTubeSharerUploadingVideoMetadata;
self.requestTag = eWSKYouTubeSharerUploadingVideoMetadata;
self.request = theRequest;
[[ASIManager manager] addRequest:theRequest];
[[ASIManager manager] startQueue];
它究竟是如何工作的?你可以發佈你的'ASIHTTPRequest'代碼嗎? – 2012-10-16 11:26:14
問題解決了!代碼工作正常。 API響應位於標題中,因此responseData爲空:) – Patrick
良好的工作:-)不要忘記在下面發佈您的答案,然後您可以接受它。 – 2012-10-17 08:27:41