iPhone アプリで撮影した動画を Facebook にアップロードしようとしています。
アプリの .plist に追加しました
FacebookAppId、FacebookDisplayName、URLSchemes と私は自分のアプリを Facebook 開発者に登録しました。
iPhone の設定で、私のアプリは Facebook アカウントの使用を許可されています
次に、ユーザーがビデオにタイトルを付けて説明を付け、ボタンをタップして Facebook にアップロードできるようにします。
- (void)buttonRequestClickHandler:(id)sender {
if (FBSession.activeSession.isOpen) {
//this is the path to the video
NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
NSString *moviePath = [documentsDirectorya stringByAppendingPathComponent:@"/Movie"];
NSString *fullPatha = [moviePath stringByAppendingPathComponent:audioName];
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:fullPatha isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:fullPatha];
//these are the title and description of the video
NSString *titleString = self.videotitle.text;
NSString *descripString = self.descrp.text;
NSDictionary *videoObject = @{
@"title":titleString,
@"description": descripString,
[pathURL absoluteString]: videoData
};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
parameters:videoObject
HTTPMethod:@"POST"];
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error)
NSLog(@"Done: %@", result);
else
NSLog(@"Error: %@", error.localizedDescription);}];
}
ここでエラー The operation could not be completed.(com.facebook.sdk error 2.) が発生するので、明らかに appDelegate からセッションを取得しておらず、ここにもログインしていません。
else {
permissions = [NSMutableArray arrayWithObjects:@"publish_actions",@"publish_streams",nil];
[FBSession openActiveSessionWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// if login fails for any reason, we alert THIS IS THE ERROR I GET
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
// if otherwise we check to see if the session is open, an alternative to
// to the FB_ISSESSIONOPENWITHSTATE helper-macro would be to check the isOpen
// property of the session object; the macros are useful, however, for more
// detailed state checking for FBSession objects
} else if (FB_ISSESSIONOPENWITHSTATE(status)) {
// send our requests if we successfully logged in
NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
NSString *moviePath = [documentsDirectorya stringByAppendingPathComponent:@"/Movie"];
NSString *fullPatha = [moviePath stringByAppendingPathComponent:audioName];
NSString *titleString = self.videotitle.text;
NSString *descripString = self.descrp.text;
NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:fullPatha isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:fullPatha];
NSDictionary *videoObject = @{
@"title":titleString,
@"description": descripString,
[pathURL absoluteString]: videoData};
FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
parameters:videoObject
HTTPMethod:@"POST"];
[uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error)
NSLog(@"Done: %@", result);
else
NSLog(@"Error: %@", error.localizedDescription);}];
}}];
}}
セッションへのログインで私が何か間違ったことをした場所を誰でも見ることができますか?
これについて誰か助けていただければ幸いです。