简体   繁体   English

无法使用iOS应用发布到Facebook

[英]Cannot post to Facebook using iOS app

I am creating an iOS app. 我正在创建一个iOS应用程序。 I need to post some links to Facebook events using my app. 我需要使用我的应用程序发布一些链接到Facebook事件。 I have integrated Facebook SDK. 我已经集成了Facebook SDK。 By using Facebook Graph API, i found the code for the same and it works fine in Graph API Explorer. 通过使用Facebook Graph API,我找到了相同的代码,它在Graph API Explorer中工作正常。 But it does not working in my app. 但它不适用于我的应用程序。 When trying to post the link to Facebook,it shows the following error. 当试图将链接发布到Facebook时,它显示以下错误。 I am using Xcode 7.3 and iOS 9. 我正在使用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;

My code is given below. 我的代码如下。

-(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");

            }
        }];

    }

And i have looked into https://developers.facebook.com/docs/ios/ios9 and tried all the combination of LSApplicationQueriesSchemes in my info.plist.Please help me.What is the problem? 我已经查看了https://developers.facebook.com/docs/ios/ios9并在我的info.plist中尝试了LSApplicationQueriesSchemes的所有组合。请帮助我。问题是什么? Why i can't post to Facebook? 为什么我不能发布到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