1

Here is my codes, which can upload video to youtube successfully. It is using user name and password, but I am going to use access token instead.Thank you very much.

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

1 Answer 1

0

Thanks this topic :http://stackoverflow.com/questions/8228212/gdata-java-client-oauth2-access-token-secret, I solve this problem throuth modifying gdata.

Firstly, modify requestForURL function in file GDataServiceGoogle.m like below:

...
// 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;

Secondly ,in function youTubeService added :

//[service setUserCredentialsWithUsername:StrUserName_ password:StrPassword_]; don't need anymore

[service setAuthToken:@"my access token"];

Further more, I use the newest version gdata.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.