【问题标题】:Cannot post to Facebook using iOS app无法使用 iOS 应用发布到 Facebook
【发布时间】:2017-04-10 11:09:10
【问题描述】:

我正在创建一个 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 上发帖?

【问题讨论】:

标签: ios objective-c iphone facebook facebook-graph-api


【解决方案1】:
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];
      }];

【讨论】:

    猜你喜欢
    • 2011-11-21
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多