关于FBSDKGraphRequest的视频分享

时间:2015-08-28 05:31:17

标签: ios objective-c iphone facebook

 if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
{

    NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"rabbit" ofType:@"mp4"]]];

    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:@"/me/videos"
                                  parameters:@{@"source":videoData}
                                  HTTPMethod:@"POST"];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,
                                          NSError *error) {

        if (result) {
            NSLog(@"video shared successfully !!!!!!!! %@",result);

        }
        else{
            NSLog(@"Error %@",error.description);

    }
                 // Handle the result
    }];
     }

我尝试了这段代码,但它不起作用......有人可以告诉我们如何在FBSDKGraphRequest上实现视频共享。  提前谢谢。

2 个答案:

答案 0 :(得分:0)

这是正确的代码。首先从Facebook Review授予“publish_actions”权限。

NSData *videoData = [NSData dataWithContentsOfFile:filePath];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   videoData, @"video.mov",
                                   @"video/quicktime", @"contentType",
                                   @"Title Text", @"title",
                                   @"Desciption Text", @"description",
                                   nil];

    FBRequest *request = [FBRequest requestWithGraphPath:@"me/videos"
                                              parameters:params
                                              HTTPMethod:@"POST"];

    FBRequestConnection *connection = [[FBRequestConnection alloc] init];

    [connection addRequest:request
         completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {


             if (!error) {

                 NSLog(@"Video uploaded successfuly! %@",result);

             } else {

                 NSLog(@"Video uploaded failed :( %@",error.userInfo);

             }



         }];

    [connection start];

答案 1 :(得分:0)

$value['name']