2010-10-28 37 views
0

我試圖上傳到喜愛的視頻在我的帳戶,但它顯示無效請求的URI和狀態碼= 400如何上傳視頻到目標C使用GDATA最愛/播放列表

我不明白應該如何格式化我的請求

我的代碼

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.but不知道如何通過在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 =包含字符串形式的XML數據

+0

我想添加到您管帳! – Swati 2010-10-28 06:58:26

回答

2
NSString *developer_key; 

GDataEntryYouTubeFavorite *favorite = [GDataEntryYouTubeFavorite entry]; 

[favorite setIdentifier:video_id]; 

service = [[GDataServiceGoogleYouTube alloc] init]; 

[service setUserCredentialsWithUsername:user_name password:user_pass]; 

[service setYouTubeDeveloperKey:developer_key]; 

NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"default" 
           userFeedID:kGDataYouTubeUserFeedIDFavorites]; 

[service fetchEntryByInsertingEntry:favorite forFeedURL:feedURL 
          delegate:self 
       didFinishSelector:@selector(subscribeTicket:finishedWithEntry:)]; 
0

有很多錯誤的要求:它缺乏的ClientLogin或OAuth認證令牌,有沒有內容長度,將XML缺少命名空間和可能其他問題。

您是否考慮過使用GData Objective-C client library?使用該庫,添加喜歡的是這樣的:

NSURL *favoritesFeedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:username 
                   userFeedID:kGDataYouTubeUserFeedIDFavorites]; 
    GDataServiceGoogleYouTube *service = [self youTubeService]; 
    [service fetchFeedWithURL:favoritesFeedURL 
      completionHandler:^(GDataServiceTicket *ticket, GDataFeedBase *feed, NSError *error) { 

      if (error == nil) { 
       // add the new favorite 
       GDataEntryYouTubeVideo *entry = [GDataEntryYouTubeVideo videoEntry]; 
       [entry setIdentifier:videoID]; 

       [service fetchEntryByInsertingEntry:entry 
             forFeedURL:[[feed postLink] URL] 
           completionHandler:^(GDataServiceTicket *ticket, GDataEntryBase *entry, NSError *error) { 

            if (error == nil) { 
            // succeeded 
            } else { 
            NSLog(@"Error inserting new favorite: %@", error); 
            } 
           }]; 

      } else { 
       NSLog(@"Error fetching favorites feed: %@", error); 
      } 

      }]; 
+0

一些錯誤:1)_Block_object_dispose,2)_NSConcreteGlobalBlack,3)_Block_object_assign,4)_NSConcreteStackBlock – Swati 2010-11-08 04:34:45

+0

一些警告:1)GDataServiceGoogleYouTube可能不fetchFeedWithURL 2響應)GDataServiceGoogleYouTube可能不fetchEntryByInsertingEntry 3響應)GDataServiceGoogleYouTube可能不youTubeService – Swati 2010-11-08 06:10:53

+0

響應是有任何方式來實現這一點,而不使用PLBlocks?如果不是,你可以建議我如何避免錯誤和警告 – Swati 2010-11-08 09:51:51