Why suddenly my iOS app can not post status update to Facebook

馋奶兔 提交于 2019-12-08 02:53:27

问题


I was able to post a status update to Facebook user wall through the iOS app I'm developing a few days ago. Then I probably accidentally removed something, I now cannot post and get error message. The relevant code is A:

    message = @"test";
    [FBRequestConnection startForPostStatusUpdate:message
    completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    }

I also tried following method B:

    [FBRequestConnection startWithGraphPath:@"me/feed" parameters:postParams HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection,id result,NSError *error)

and I got same error message: The operation couldn’t be completed. (com.facebook.sdk error 5.)"

I also noticed doesn't matter if I use FacebookSDK.h or Facebook.h for either method, both (four ways) would all get the same error message above. I also wonder why FacebookSDK.h is enough to support two methods above, why the tutorial suggests deprecated Facebook.h.

Interesting, I went to check another testing iOS app that I remember could post Facebook status update, and found it could not post either. Any idea?


回答1:


I decided to use iOS6 feature SLComposeViewController, which makes posting Facebook status update a piece of cake.

After add Social framework in your .m file, you can do sth like this:

    - (IBAction)clickMe:(UIButton *)sender {
         NSLog(@"you clicked me");
         if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

       SLComposeViewController* myFB = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];


          SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result) {
            if (result == SLComposeViewControllerResultCancelled) {
                NSLog(@"cancelled");
           } else {
               NSLog(@"oh yeah");
           }
        [myFB dismissViewControllerAnimated:YES completion:nil];
    };
    myFB.completionHandler = myBlock;
    [myFB setInitialText:@"Posting from my app."];
    [self presentViewController:myFB animated:YES completion:nil];

    }

    }


来源:https://stackoverflow.com/questions/12540895/why-suddenly-my-ios-app-can-not-post-status-update-to-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!