0

我正在使用以下代码在 facebook 上发布照片。

if ([FBDialogs canPresentShareDialogWithPhotos])
{


    FBShareDialogPhotoParams *params = [[FBShareDialogPhotoParams alloc] init];

    // Note that params.photos can be an array of images.  In this example
    // we only use a single image, wrapped in an array.
    params.photos = @[imageDetails.chosenImage];
    params.place=@"Abracadabra Snap! ios application";
    [FBDialogs presentShareDialogWithPhotoParams:params
                                     clientState:nil
                                         handler:^(FBAppCall *call,
                                                   NSDictionary *results,
                                                   NSError *error) {
                                             if (error) {
                                                 NSLog(@"Error: %@",
                                                       error.description);
                                             } else {
                                                 NSLog(@"Success!");
                                             }
                                         }];
}

它向我显示了一个对话框,我在其中写了一些文本并单击帖子,在我单击帖子后,它上传图像并返回到调用控制器,但不返回错误或成功,也不在 facebook 上发布图像任何一个。请帮忙解决这个问题

4

2 回答 2

2

试试这个......在分享按钮......

- (IBAction)facebookPost:(id)sender 
{    
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {

        SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [mySLComposerSheet setInitialText:@"ABC"];

        [mySLComposerSheet addImage:[UIImage imageNamed:@"abc.png"]];

        [mySLComposerSheet addURL:[NSURL URLWithString:@"google.com"]];

        [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) 
        {

            switch (result)
            {
                case SLComposeViewControllerResultCancelled:
                {
                    NSLog(@"Post Canceled");
                    break;
                }

                case SLComposeViewControllerResultDone:
                { 
                    NSLog(@"Post Sucessful");
                    break;
                }

                default:
                    break;
            }
        }];

        [self presentViewController:mySLComposerSheet animated:YES completion:nil];
    }
}
于 2014-04-09T12:57:19.310 回答
0

将以下代码添加到您的 appdelegate,这可确保 facebook 应用程序可以将数据发送回您的应用程序。(取自:https ://developers.facebook.com/docs/ios/share )

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    BOOL urlWasHandled = [FBAppCall handleOpenURL:url
                                sourceApplication:sourceApplication
                                  fallbackHandler:^(FBAppCall *call) {
                                      NSLog(@"Unhandled deep link: %@", url);
                                      // Here goes the code to handle the links
                                      // Use the links to show a relevant view of your app to the user
                                  }];

    return urlWasHandled;
}
于 2014-05-22T11:16:14.827 回答