2015-08-28 97 views
0
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上的視頻共享。 在此先感謝。視頻分享FBSDKGraphRequest

+0

你能否解釋一下你所說的「代碼不工作」是什麼意思? – Amila

+0

代碼正在工作,但視頻不在Facebook上共享 – Anitha

回答

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

此代碼在最新的fbsdk中解除壓縮。請您在此幫助 – Anitha

+0

這不會被棄用。我剛剛使用了3天前。這是API V2.4 –

+0

的最新版本您是否授予Facebook審閱的publish_action權限? –

0
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init]; 
[loginManager logOut]; 

[loginManager logInWithPublishPermissions:@[@"publish_actions"] 
            handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
             if(error!=nil) 
             { 
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init]; 
    [params setObject:dataVideoCompress forKey:@"abc.mov"]; 
[[[FBSDKGraphRequest alloc]initWithGraphPath:@"/me/videos" parameters:params tokenString:[FBSDKAccessToken currentAccessToken].tokenString version:FBSDK_TARGET_PLATFORM_VERSION HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) 
              { 
               if(error!=nil) 
               { 
               } 
              }]; 
              } 
}];