我尝试使用GData API从我的iPhone应用程序内部向youtube发布视频。以下是我使用的代码:
GDataServiceGoogleYouTube* service = [self youTubeService];
[service setYouTubeDeveloperKey:youtubeAppKey];
NSString *username = service.username;
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];
NSData *data = [NSData dataWithContentsOfFile:self.videoPath];
NSString *filename = @"My Cool Video";
NSString *titleStr = @"Title";
GDataMediaTitle *mediaTitle = [GDataMediaTitle textConstructWithString:titleStr];
NSString *categoryStr = @"Comedy";
GDataMediaCategory *mediaCategory = [GDataMediaCategory mediaCategoryWithString:categoryStr];
[mediaCategory setScheme:kGDataSchemeYouTubeCategory];
NSString *descStr = @"Description";
GDataMediaDescription *mediaDesc = [GDataMediaDescription textConstructWithString:descStr];
NSString *keywordsStr = @"iOS";
GDataMediaKeywords *mediaKeywords = [GDataMediaKeywords keywordsWithString:keywordsStr];
GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:mediaTitle];
[mediaGroup setMediaDescription:mediaDesc];
[mediaGroup addMediaCategory:mediaCategory];
[mediaGroup setMediaKeywords:mediaKeywords];
[mediaGroup setIsPrivate:isPrivate];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:self.videoPath
defaultMIMEType:@"video/mp4"];
GDataEntryYouTubeUpload *entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
data:data
MIMEType:mimeType
slug:filename];
GDataServiceTicket *ticket = [service fetchEntryByInsertingEntry:entry
forFeedURL:url
delegate:self
didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];
[self setUploadTicket:ticket];
我得到了这样的答复:
serviceBase:objectFetcher:GTMHTTPUploadFetcher 0x48af0a0(https://uploads.gdata.youtube.com/resumable/feeds/api/users/myCoolMail@gmail.com/uploads?upload_id=heregoesidiremoved)failedWithStatus:400 data:GData {{ 1}}异常消息不可用
我尝试了Google示例代码并获得了相同的结果。我使用了设备和模拟器(5.0)。我已经尝试过准备好的视频,只要从iPhone录制一个。 我在google API部分创建了Project,并获得了一个应用程序密钥。
请帮我找到解决问题的方法!
答案 0 :(得分:10)
问题在于:
NSString *username = service.username;
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];
不知道为什么会这样,但我已经将userID从“username”更改为kGDataServiceDefaultUser,并且该东西开始工作了。如此简单和如此奇怪,但它确实做到了。
正确的代码:
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:kGDataServiceDefaultUser];