开发者

ServiceForbiddenException when uploading video to youtube via iphone application

开发者 https://www.devze.com 2023-02-05 03:48 出处:网络
I use GData try to upload my video to YouTube, but meet this error: serviceBase:<GDataServiceGoogleYouTube: 0x2435f0> objectFetcher:<GDataHTTPUploadFetcher: 0x26dca0> failedWithStatus:403

I use GData try to upload my video to YouTube, but meet this error:

serviceBase:<GDataServiceGoogleYouTube: 0x2435f0> objectFetcher:<GDataHTTPUploadFetcher: 0x26dca0> failedWithStatus:403 data:<errors xmlns='http://schemas.google.com/g/2005'>
<error>
<domain>GData</domain>
<code>ServiceForbiddenException</code>
<internalReason>Currently authenticated user does not have write access to ******&ap开发者_C百科os;s videos.</internalReason>
</error>
</errors>

******* is my youtube account.

Following is the code:

- (GDataServiceGoogleYouTube *)youTubeService 
{

    static GDataServiceGoogleYouTube* service = nil;

    if (!service) {
        service = [[GDataServiceGoogleYouTube alloc] init];

        [service setShouldCacheDatedData:YES];
        [service setServiceShouldFollowNextLinks:YES];
        [service setIsServiceRetryEnabled:YES];
    }

    // update the username/password each time the service is requested
    NSString *username = [mUsernameField text];
    NSString *password = [mPasswordField text];

    if ([username length] > 0 && [password length] > 0) {
        [service setUserCredentialsWithUsername:username
                                       password:password];
    } else {
        // fetch unauthenticated
        [service setUserCredentialsWithUsername:nil
                                       password:nil];
    }

    NSString *devKey = [mDeveloperKeyField text];
    [service setYouTubeDeveloperKey:devKey];

    return service;
}

- (IBAction)uploadPressed:(id)sender {

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

}

It's almost the same as GData's YouTubeSample.

What could be the reason for the exception?

0

精彩评论

暂无评论...
验证码 换一张
取 消