7

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

YouTubeTest[2149:f803] 错误 - 错误域 = com.google.GDataServiceDomain 代码 = 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 Dashboard 正确设置了开发者密钥和客户端密钥。

我在模拟器上运行它。我们不能从模拟器上传视频吗?

请指导我哪里出错了?

4

1 回答 1

3

错误解决... 当使用谷歌账号上传视频到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 登录。多么愚蠢的错误!..但我花了整整 2 天时间才解决.. Duhhh ..!!

于 2012-06-12T21:05:14.980 回答