1

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

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

其他时候什么都没有出现。我希望用户仅在单击 Facebook 中的“共享图像”时登录。这就是为什么我没有将代表放在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+ 和其他所有内容中轻松分享照片?

4

1 回答 1

2

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

      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 .....
于 2012-04-13T08:13:54.120 回答