我正在尝试将照片上传到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 +以及其他所有内容中轻松分享照片?
答案 0 :(得分: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 .....