簡體   English   中英

無法使用iOS應用發布到Facebook

[英]Cannot post to Facebook using iOS app

我正在創建一個iOS應用程序。 我需要使用我的應用程序發布一些鏈接到Facebook事件。 我已經集成了Facebook SDK。 通過使用Facebook Graph API,我找到了相同的代碼,它在Graph API Explorer中工作正常。 但它不適用於我的應用程序。 當試圖將鏈接發布到Facebook時,它顯示以下錯誤。 我正在使用Xcode 7.3和iOS 9。

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中嘗試了LSApplicationQueriesSchemes的所有組合。請幫助我。問題是什么? 為什么我不能發布到Facebook?

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:
                                 fbOutput=@"You Post is cancelled";
                                 break;

                        case SLComposeViewControllerResultDone:
                                 fbOutput=@"Your post Posted Succesfully";
                                 break;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM