Youtube API身份验证

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

YouTubeTest [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];

}

我已经从API仪表板正确设置了开发人员密钥和客户端密钥。

我在模拟器上运行这个。 难道我们不能从模拟器上传视频吗?

请指导我我哪里错了?


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

当你调用' - (void)setUserCredentialsWithUsername:(NSString *)username password:(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登录。多么愚蠢的错误!..但是花了我整整两天的时间来解决.. Duhhh .. !!

链接地址: http://www.djcxy.com/p/10839.html

上一篇: Youtube API Authentication

下一篇: How to have password echoed as asterisks