Youtube API身份验证 - Iphone [英] Youtube API Authentication - Iphone

查看:262
本文介绍了Youtube API身份验证 - Iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用youtube api的示例代码上传视频。
当我按下上传按钮时,进度条完成其过程,但一旦到达终点,我就会收到错误。错误描述如下:

I am trying to upload video using sample code of youtube api. When i press upload button, the progress bar finishes its process, but once when it reaches end of point i get error. Error description is as follows :


YouTubeTest [2149:f803]错误 - 错误
Domain = com.google.GDataServiceDomain Code = 400该操作无法完成
。(com.google.GDataServiceDomain错误400.)
UserInfo = 0x69d5bd0 {}

YouTubeTest[2149:f803] error - Error Domain=com.google.GDataServiceDomain Code=400 "The operation couldn’t be completed. (com.google.GDataServiceDomain error 400.)" UserInfo=0x69d5bd0 {}

这是按下上传按钮的代码

This is code for upload button pressed

- (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正确设置了开发人员密钥和客户端密钥仪表板。

I have set up developer key and client key correctly from API Dashboard.

我在模拟器上运行它。是不是我们无法从模拟器上传视频?

I am running this on simulator. Is it we can not upload videos from simulator?

请指导我哪里出错?

推荐答案

解决了错误...
使用Google帐户将视频上传到YouTube时,GData的某些功能
Objective-C需要Gmail帐户作为参数,有些需要
YouTube关联帐户作为参数。

Error Solved... When using a Google account to upload video to YouTube, some functions of the GData Objective-C require the Gmail account as parameter and some require the YouTube linked account as parameter.

当你调用' - (void)setUserCredentialsWithUsername:(NSString *)
用户名密码:(NSString *)密码;'在GDataServiceBase中,
用户名应为Gmail帐户,例如
'x ... @ gmail.com',密码应为
Gmail帐户的密码。

When you call '- (void)setUserCredentialsWithUsername:(NSString *) username password:(NSString *)password;' in GDataServiceBase, the username should be the Gmail account, for example 'x...@gmail.com' and the password should be the password of the Gmail account.

但是当你调用'+(NSURL *)youTubeUploadURLForUserID:(NSString *)
userID clientID:(NSString *)clientID;'在GDataServiceGoogleYouTube中,
userID参数应该是YouTube链接的帐户和
密码是Gmail帐户的密码。

But when you call '+ (NSURL *)youTubeUploadURLForUserID:(NSString *) userID clientID:(NSString *)clientID;' in GDataServiceGoogleYouTube, the userID parameter should be the YouTube linked account and the password the password of the Gmail account.

我正在使用email_id@gmail.com登录现在我只使用email_id登录。真是个愚蠢的错误!..但是花了我整整2天解决.. Duhhh .. !!

I was using email_id@gmail.com to log in where now i am just using email_id to log in. What a silly error!.. But took me 2 full days to solve.. Duhhh..!!

这篇关于Youtube API身份验证 - Iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆