【问题标题】:How to upload video to youtube with gdata in objective-c using access token如何使用访问令牌在objective-c中使用gdata将视频上传到youtube
【发布时间】:2012-11-22 07:54:33
【问题描述】:

这是我的代码,可以成功将视频上传到 youtube。它正在使用用户名和密码,但我将使用访问令牌。非常感谢。

GDataServiceGoogleYouTube *service = [self youTubeService];
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:kGDataServiceDefaultUser
                                                             clientID:@"test"];
    NSData *data = [NSData dataWithContentsOfFile:videoPath];
    NSString *filename = [videoPath lastPathComponent];
    GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:strVideoTitle_];
    GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:strCategory_];
    [category setScheme:kGDataSchemeYouTubeCategory];
    GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:strVideoDescription];
    GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:strkeyWord_];
    GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
    [mediaGroup setMediaTitle:title];
    [mediaGroup setMediaDescription:desc];
    [mediaGroup addMediaCategory:category]; 
    [mediaGroup setMediaKeywords:keywords];
    [mediaGroup setIsPrivate:isPrivate_];
    NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:videoPath
                                               defaultMIMEType:@"video/mp4"]; 
    GDataEntryYouTubeUpload *entry;
    entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
                                                          data:data
                                                      MIMEType:mimeType
                                                          slug:filename];
    SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
    [service setServiceUploadProgressSelector:progressSel];
    gDataServiceTicket_ =  [[service fetchEntryByInsertingEntry:entry
                                       forFeedURL:url
                                         delegate:self
                                didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)] retain];

【问题讨论】:

    标签: objective-c youtube


    【解决方案1】:

    感谢这个话题:http://stackoverflow.com/questions/8228212/gdata-java-client-oauth2-access-token-secret,我通过修改gdata解决了这个问题。

    首先,修改 GDataServiceGoogle.m 文件中的 requestForURL 函数,如下所示:

    ...
    // add the auth token to the header if ([authToken length] > 0) 
    { 
    //NSString *value = [NSString stringWithFormat:@"GoogleLogin auth=%@", authToken]; 
    NSString *value = [NSString stringWithFormat:@"Bearer %@", authToken]; 
    [request setValue:value forHTTPHeaderField: @"Authorization"]; } 
    else if ([authSubToken_ length] > 0) 
    { NSString *value = [NSString stringWithFormat:@"AuthSub token=%@", authSubToken_]; 
    [request setValue:value forHTTPHeaderField: @"Authorization"]; 
    } 
    return request;
    

    其次,在youTubeService函数中添加:

    //[服务setUserCredentialsWithUsername:StrUserName_密码:StrPassword_];不需要了

    [服务 setAuthToken:@"我的访问令牌"];

    此外,我使用最新版本的 gdata。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-08
      • 2012-12-20
      • 2015-06-12
      • 2012-03-31
      • 2012-06-07
      • 1970-01-01
      • 2011-06-13
      相关资源
      最近更新 更多