Youtube API身份验证 - Iphone

inn*_*pps 7 iphone upload youtube-api ios ios-simulator

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

YouTube测试[2149:f803]错误 - 错误域= com.google.GDataServiceDomain代码= 400"无法完成操作.(com.google.GDataServiceDomain错误400.)"UserInfo = 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];

}
Run Code Online (Sandbox Code Playgroud)

我已经从API Dashboard正确设置了开发人员密钥和客户端密钥.

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

请指导我哪里出错了?

inn*_*pps 3

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

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

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

我以前使用 email_id@gmail.com 登录,现在我只是使用 email_id 登录。多么愚蠢的错误!..但是花了我整整 2 天的时间来解决.. Duhhh..!!