Gdata youtube上传failedWithStatus:400

时间:2011-11-29 16:17:43

标签: objective-c ios xcode youtube gdata

我有一个小应用,我使用gdata将视频上传到youtube。每次我尝试,我都会收到以下错误:“serviceBase:objectFetcher:failedWithStatus:400 data:GData InvalidRequestUriException用户名丢失或无效。”

我尝试使用我的youtube accout,或者我的gmail accout,但都没有用。任何帮助将不胜感激。

这是代码:

NSString *devKey = DEVELOPER_KEY;

GDataServiceGoogleYouTube *service = [self youTubeService];
[service setYouTubeDeveloperKey:devKey];

NSString *username = @".........@gmail.com";
NSString *clientID = CLIENT_ID;

NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username
                                                         clientID:clientID];

// load the file data

NSString  *videoPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/output.mp4"];

//    NSString *path = [[NSBundle mainBundle] pathForResource:@"YouTubeTest" ofType:@"m4v"]; 
NSData *data = [NSData dataWithContentsOfFile:videoPath];
NSString *filename = [videoPath lastPathComponent];

// gather all the metadata needed for the mediaGroup
NSString *titleStr = [titleTextField text];
GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];

NSString *categoryStr = [mCategoryField text];
GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
[category setScheme:kGDataSchemeYouTubeCategory];

NSString *descStr = [mDescriptionField text];
GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];

NSString *keywordsStr = [mKeywordsField text];
GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];

BOOL isPrivate = mIsPrivate;

GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:title];
[mediaGroup setMediaDescription:desc];
[mediaGroup addMediaCategory:category];
[mediaGroup setMediaKeywords:keywords];
[mediaGroup setIsPrivate:isPrivate];


NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:videoPath defaultMIMEType:@"video/mp4"];

// create the upload entry with the mediaGroup and the file data
GDataEntryYouTubeUpload *entry;

NSLog(@"%@", mimeType);

entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
                                                      data:data
                                                  MIMEType:mimeType
                                                      slug:filename];

SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
[service setServiceUploadProgressSelector:progressSel];

GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:entry
                                  forFeedURL:url
                                    delegate:self
                           didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];

[self setUploadTicket:ticket];

}

1 个答案:

答案 0 :(得分:0)

错误代码400是错误请求“无效的请求URI或标头,或不支持的非标准参数”。这基本上意味着您错误地格式化了您的请求。 HTTP Status Codes链接以解释所有错误代码。

您可以发布用于上传视频的代码吗?

编辑: 您可以使用YouTube Sample上传吗?

如果这样可以正常工作,它将证明你的devkey工作正常。它还将表明这些线路存在问题:

NSString *username = @".........@gmail.com";
NSString *clientID = CLIENT_ID;

NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username
                                                     clientID:clientID];

NSString  *videoPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/output.mp4"];

如果示例YouTube示例正在运行,那么问题就是

  1. 客户端尚未使用您的devkey进行身份验证。 或
  2. videoPath不是正确的位置。