ios - 发布照片 Facebook iOS

标签 ios facebook

我正在尝试将照片上传到 Facebook。我阅读了很多教程和示例,但仍然无法正常工作。很多时候我在这一行得到一个 EXC_BAD_ACCESS:

[_facebook requestWithGraphPath:@"me/photos"
                                 andParams:photosParams
                             andHttpMethod:@"POST"
                               andDelegate:self];  

其他时候什么也没有出现。我希望用户仅在单击 Facebook 中的“共享图像”时才登录。这就是为什么我没有将委托(delegate)放在 appDelegate 中的原因。下面是我的代码:

if (_facebook != nil)  {
        [self fbDidLogin];
    }  

    _publishedImage = img;
    _facebook = [[Facebook alloc] initWithAppId:@"235694579858240" andDelegate:self];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) 
    {
        _facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        _facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    if (![_facebook isSessionValid])
    {
        NSArray* permissions = [[NSArray alloc] initWithObjects:
                                @"offline_access", @"publish_stream", @"publish_actions", @"photo_upload", nil];

        [_facebook authorize:permissions];
    }

    UIImage *imgSource = img;
    NSString *strMessage = @"This is the photo caption";
    NSMutableDictionary* photosParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                         imgSource,@"source",
                                         strMessage,@"message",
                                         nil];

    [_facebook requestWithGraphPath:@"me/photos"
                                     andParams:photosParams
                                 andHttpMethod:@"POST"
                                   andDelegate:self]; 

我的 ViewController 有这些代表:

<UIImagePickerControllerDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, MFMailComposeViewControllerDelegate, FBSessionDelegate, FBDialogDelegate, FBRequestDelegate>

编辑:是否有任何插件可以轻松地在 Facebook、G+ 和其他任何地方轻松分享照片?

最佳答案

为什么不使用图表而不是尝试:

      if ([fbAppDelegate.facebook isSessionValid]) {
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:                                                                       @"http://hd.ipad-wallpapers.fr/thumbs/wooden_apple_logo_4-t1.jpg // but could also use UIImage", @"picture", nil]; // you don't



    [fbAppDelegate.facebook dialog:@"feed" andParams:params andDelegate:self];

}

// this is what I do .....

关于ios - 发布照片 Facebook iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10137151/

相关文章:

ios - 在 SceneKit 中,当从 RunAction 的完成处理程序调用时,SCNAction 挂起

ios - Google Maps myLocationButton 在 Tab Bar Controller Swift 3 下

ios - Swift 如何阻止标签栏改变背景颜色

ios - UIViewController继承: Passing parameters to a parent class that is a subclass of UIViewController

ios - 代号一 Native IOS实现错误: . h文件未找到

facebook - 共享按钮不显示来自共享链接的图像

javascript - 如何调试我网站上的 Facebook JavaScript api 错误?

ios - NSFetchedResultsController 全部删除

javascript - Facebook 未捕获的安全错误

javascript - ie8 中的 facebook api 问题