1

iphoneアプリからyoutubeにビデオをアップロードする必要があります。googleoauthからアクセストークンを取得しましたが、ビデオをアップロードするための投稿リクエストでASIFormDataRequestを使用しているため、youtubeにビデオをアップロードするときに問題が発生します。以下は私のコードです。よろしくお願いします。私の間違いを解決するのを手伝ってください。

- (IBAction)buttonTouched:(id)sender
{
    NSLog(@"%d %@",[sender tag],[[NSUserDefaults standardUserDefaults] valueForKey:@"access_token"]);

    progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30, 90, 200, 20.0)];
    [alertView addSubview:progressView];
    [alertView show];
    [progressView setProgress:0];   

    NSString *name=[videosToShow objectAtIndex:[sender tag]];
    NSString *newFilePath = [NSString stringWithFormat:@"%@.mov", [self.path stringByAppendingPathComponent:name]];
    NSLog(@"Content URL :%@;", newFilePath);

    NSURL *url = [NSURL URLWithString:@"https://uploads.gdata.youtube.com/feeds/api/users/default/uploads"];

    ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];

    [request setRequestMethod:@"POST"];

    NSLog(@"Auth Token== %@",[[NSUserDefaults standardUserDefaults] valueForKey:@"access_token"]);

    [request setPostValue:[[NSUserDefaults standardUserDefaults] valueForKey:@"access_token"] forKey:@"authentication_token"];

    [request setPostValue:devKey forKey:@"developer_key"];

    [request setPostValue:@"abcabc" forKey:@"boundary_string"];

    [request setPostValue:devKey forKey:@"content_length"];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"xmlcontent" ofType:@"txt"];
    NSString *strXml = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

    [request setPostValue:strXml forKey:@"API_XML_Request"];

    [request setPostValue:@"video/mov" forKey:@"video_content_type"];

    [request setPostValue:@"video/mov" forKey:@"Binary File Data"];

    [request setFile:newFilePath withFileName:@"1.mov" andContentType:@"video/mov" forKey:@"uploaded"];

    [request setUploadProgressDelegate:self];
    [request setDelegate:self];

    [request setDidFinishSelector:@selector(requestFinished:)];
    [request setDidFailSelector:@selector(requestFailed:)]; 

    [request setShowAccurateProgress:YES];
    [request startAsynchronous];
}

- (void)requestFinished:(ASIFormDataRequest *)request {
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congrats!!!" message:@"File has been downloaded." 
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
}

- (void)requestFailed:(ASIFormDataRequest *)request1 {
    NSError *error = [request1 error];
    NSLog(@"%@", error);
}

以下はファイルxmlcontent.txtです

<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Bad Wedding Toast</media:title>
<media:description type="plain">
I gave a bad toast at my friend's wedding.
</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
</media:category>
<media:keywords>toast, wedding</media:keywords>
</media:group>
</entry>

以下は私が得ているエラーです

エラードメイン=ASIHTTPRequestErrorDomainコード=3「認証が必要です」UserInfo=0x1c8ed0{NSLocalizedDescription=認証が必要です}

4

1 に答える 1