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 に答える