2016-11-26 23 views
1

我正在創建一個iOS應用。我需要使用我的應用程序發佈一些到Facebook事件的鏈接。我已經整合了Facebook SDK。通過使用Facebook Graph API,我發現了相同的代碼,並且它在Graph API Explorer中正常工作。但它不適用於我的應用程序。嘗試將鏈接發佈到Facebook時,會顯示以下錯誤。我正在使用Xcode 7.3和iOS 9.無法使用iOS應用發佈到Facebook

error=Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=403, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=(#200) Insufficient permission to post to target on behalf of the viewer, com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=200, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={ 
body =  { 
    error =   { 
     code = 200; 
     "fbtrace_id" = DWR8SW4K1Ls; 
     message = "(#200) Insufficient permission to post to target on behalf of the viewer"; 
     type = OAuthException; 
    }; 
}; 
code = 403; 

我的代碼如下。

-(void)postToFacebook 
{ 

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

     [self post]; 
     // TODO: publish content. 
    } else { 
     FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init]; 
     [loginManager logInWithPublishPermissions:@[@"publish_actions"] 
           fromViewController:self 
              handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
               if(error) 
               { 
                NSLog(@"error=%@",error); 
               } 
               else{ 
                [self post]; 
               } 

               //TODO: process error or result. 
              }]; 
    } 
} 

-(void)post 
    { 

     FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] 
             initWithGraphPath:3466734743/feed 
             parameters:@{ @"link": @"http://www.dhip.in/ofc/metatest.html",} 
             HTTPMethod:@"POST"]; 
     [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
      // Insert your code here 

      if(error) 
      { 
       NSLog(@"error=%@",error); 
      } 
      else 
      { 
       NSLog(@"success"); 

      } 
     }]; 

    } 

,我已經看着https://developers.facebook.com/docs/ios/ios9,儘量把info.plist.Please幫助me.What LSApplicationQueriesSchemes的所有組合是什麼問題?爲什麼我不能發佈到Facebook?

+0

檢查錯誤以這個答案:http://stackoverflow.com/a/19653226/3202193 –

回答

0
SLComposeViewController *fbCompose; 

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { 
       fbCompose=[[SLComposeViewController alloc]init]; 
       fbCompose=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 
       [fbCompose setInitialText:@"My Score in AlphaMarics is"]; 
       [fbCompose addImage:image]; 

       [self presentViewController:fbCompose animated:YES completion:nil]; 

    } 
    [fbCompose setCompletionHandler:^(SLComposeViewControllerResult result) 
     { 
       NSString * fbOutput=[[NSString alloc]init]; 
       switch (result){ 
         case SLComposeViewControllerResultCancelled: 
           [email protected]"You Post is cancelled"; 
           break; 

         case SLComposeViewControllerResultDone: 
           [email protected]"Your post Posted Succesfully"; 
           break; 

         default: 
           break; 
       } 
       UIAlertView * fbAlert=[[UIAlertView alloc]initWithTitle:@"Warning" message:fbOutput delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 
       [fbAlert show]; 
     }]; 
相關問題