我正在尝试使用 youtube api 的示例代码上传视频。
当我按下上传按钮时,进度条完成其过程,但是一旦到达终点我就会收到错误。错误描述如下:
YouTubeTest[2149:f803] 错误 - 错误
Domain=com.google.GDataServiceDomain Code=400 "操作无法
完成。 (com.google.GDataServiceDomain 错误 400。)”
用户信息=0x69d5bd0 {}
这是按下上传按钮的代码
- (IBAction)uploadPressed:(id)sender {
[self.view resignFirstResponder];
NSString *devKey = [mDeveloperKeyField text];
GDataServiceGoogleYouTube *service = [self youTubeService];
[service setYouTubeDeveloperKey:devKey];
NSString *username = [mUsernameField text];
NSString *clientID = [mClientIDField text];
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username
clientID:clientID];
// load the file data
NSString *path = [[NSBundle mainBundle] pathForResource:@"YouTubeTest" ofType:@"m4v"];
NSData *data = [NSData dataWithContentsOfFile:path];
NSString *filename = [path lastPathComponent];
// gather all the metadata needed for the mediaGroup
NSString *titleStr = [mTitleField 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:path
defaultMIMEType:@"video/mp4"];
// create the upload entry with the mediaGroup and the file data
GDataEntryYouTubeUpload *entry;
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];
}
我已从 API 仪表板正确设置了开发人员密钥和客户端密钥。
我正在模拟器上运行这个。是不是模拟器无法上传视频?
请指导我哪里出错了?
错误已解决...
使用Google帐户上传视频到YouTube时,GData的一些功能
Objective-C 需要 Gmail 帐户作为参数,有些需要
YouTube 链接帐户作为参数。
当您调用 '- (void)setUserCredentialsWithUsername:(NSString *)
用户名密码:(NSString *)密码;'在GDataServiceBase中,
用户名应该是 Gmail 帐户,例如
'[电子邮件受保护] /cdn-cgi/l/email-protection' 并且密码应该是
Gmail 帐户。
但是当你调用 '+ (NSURL *)youTubeUploadURLForUserID:(NSString *)
用户ID 客户端ID:(NSString *)客户端ID;'在 GDataServiceGoogleYouTube 中,
userID 参数应该是 YouTube 链接帐户并且
密码 Gmail 帐户的密码。
我正在使用[电子邮件受保护] /cdn-cgi/l/email-protection登录现在我只是使用 email_id 登录。多么愚蠢的错误!..但是花了我整整 2 天的时间来解决.. Duhhh..!!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)