iOS failure to post on Facebook, no errors logged

吃可爱长大的小学妹 提交于 2019-12-30 06:55:50

问题


I'm trying to share to Facebook using code from their iOS game tutorial. The dialog pops up and the image and text I specified is present, but when I hit "Send" the loading bar appears, doesn't load, then I am redirected to my app. No errors are printed to the console and the app does not crash.

When I go on Facebook to check if the message has posted, I get the following:

"Oops, Something Went Wrong. There was a problem posting your status. We've logged the error and will look into it."

I've used this code in the previous app and it worked perfectly fine. I've updated the Facebook ID, Facebook Display Name, and URL Scheme in the plist.

Here is the code:

FacebookHandler class (derived from Facebook tutorial)

#import "FacebookHandler.h"

@implementation FacebookHandler

+ (void) Facebook_CreateNewSession
{
    // initialize Facebook
    FBSession* session = [[FBSession alloc] init];
    [FBSession setActiveSession: session];
}

+ (void) Facebook_Login
{
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"email",
                        nil];

// Attempt to open the session. If the session is not open, show the user the Facebook login UX
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:true completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
{
    // Did something go wrong during login? I.e. did the user cancel?
    if (status == FBSessionStateClosedLoginFailed || status == FBSessionStateCreatedOpening) {

        // If so, just send them round the loop again
        [[FBSession activeSession] closeAndClearTokenInformation];
        [FBSession setActiveSession:nil];
        [self Facebook_CreateNewSession];
    }
    else
    {
    }                  
}];
}

+ (void) Facebook_PostToNewsFeedWithTitle:(NSString*)title withCaption:(NSString*)caption withDescription:(NSString*)description withLink:(NSString*)link withPictureURL:(NSString*)picURL
{

// check if user is logged in
if ([FBSession activeSession] == nil)
{
    [FacebookHandler Facebook_CreateNewSession];
    [FacebookHandler Facebook_Login];
}


// This function will invoke the Feed Dialog to post to a user's Timeline and News Feed
// It will attemnt to use the Facebook Native Share dialog
// If that's not supported we'll fall back to the web based dialog.

NSString *linkURL = link;
NSString *pictureURL = picURL;

// Prepare the native share dialog parameters
FBShareDialogParams *shareParams = [[FBShareDialogParams alloc] init];
shareParams.link = [NSURL URLWithString:linkURL];
shareParams.name = title;
shareParams.caption= caption;
shareParams.picture= [NSURL URLWithString:pictureURL];
shareParams.description = description;

if ([FBDialogs canPresentShareDialogWithParams:shareParams]){

    [FBDialogs presentShareDialogWithParams:shareParams
                                clientState:nil
                                    handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                        if(error) {
                                            NSLog(@"Error publishing story.");
                                        } else if (results[@"completionGesture"] && [results[@"completionGesture"] isEqualToString:@"cancel"]) {
                                            NSLog(@"User canceled story publishing.");
                                        } else {
                                            NSLog(@"Story published.");
                                        }
                                    }];

}else {

    // Prepare the web dialog parameters
    NSDictionary *params = @{
                             @"name" : shareParams.name,
                             @"caption" : shareParams.caption,
                             @"description" : shareParams.description,
                             @"picture" : pictureURL,
                             @"link" : linkURL
                             };

    // Invoke the dialog
    [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                           parameters:params
                                              handler:
     ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
         if (error) {
             NSLog(@"Error publishing story.");
         } else {
             if (result == FBWebDialogResultDialogNotCompleted) {
                 NSLog(@"User canceled story publishing.");
             } else {
                 NSLog(@"Story published.");
             }
         }}];
}
}
@end

My Call

    [FacebookHandler Facebook_PostToNewsFeedWithTitle:title withCaption:caption withDescription:description withLink:link withPictureURL:picURL];

UPDATE

It seems to be a problem with the Facebook app. When trying it on a device with Facebook uninstalled, I am asked to log in and then it posts successfully. However, if Facebook is installed, it doesn't post.


回答1:


I fix it by manually typing the "URL types" key at the plist file. Don't copy paste the plist values from another plist file - it's Apple's bug!!!



来源:https://stackoverflow.com/questions/24748202/ios-failure-to-post-on-facebook-no-errors-logged

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