我正在尝试将照片上传到 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/