2012-10-16 3 views
1

내가 무비 재개 업로드에 워킹했다 : 나는 다음과 같은 ASIHttpRequest와 요청을 작성하는 데 실패 https://developers.google.com/youtube/2.0/developers_guide_protocol_resumable_uploads#Sending_a_Resumable_Upload_API_Request다음과 같이 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), empty.I를 요청이 오류없이 완료,하지만 드 responseData 인 내 코드 안됩니다 왜 그런지 안다!

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]; 
+0

정확히 작동하지 않는 점은 무엇입니까? ASIHTTPRequest 코드를 게시 할 수 있습니까? –

+0

문제가 해결되었습니다. 코드가 제대로 작동합니다. API 응답이 헤더에 있으므로 responseData가 비어 있습니다. – Patrick

+0

좋은 결과 :-) 아래에 답변을 게시하는 것을 잊지 마시고 동의하십시오. –

답변

0

아래의 예는 재개 업로드 비디오 메타 데이터를 업로드 요청에 대한 샘플 API 응답을 보여줍니다

HTTP/1.1 200 OK 
Location: http://uploads.gdata.youtube.com/resumableupload/AF8GKF...0Glpk0Aw 
Date: Fri, 04 Dec 2009 16:14:30 GMT 
Pragma: no-cache 
Expires: Fri, 01 Jan 1990 00:00:00 GMT 
Cache-Control: no-cache, no-store, must-revalidate 
Content-Length: 0 
Content-Type: text/html 

코드는 잘 작동합니다. "Location"url은 본문이 아니라 헤더에 있으므로 responseData는 비어 있습니다.

0

사용 방법에 대한 정보는 the ASIHTTPRequest how-to을 참조하십시오. 대체로 다음과 같은 내용을 갖게됩니다.

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 
[request addRequestHeader:@"X-GData-Key" value:@"adf15ee97731bca89da876c...a8dc9"]; 
// add the other special headers as well 
NSString *xmlBody = // create the XML data in the body 
[request appendPostData:[xmlBody dataUsingEncoding:NSUTF8StringEncoding]]; 
[request startSynchronous]; 

백그라운드 스레드에서 동기식 요청을 수행한다고 가정합니다.

관련 문제