我正尝试将照片上传到Facebook。我阅读了很多教程和示例,但仍无法实现。很多时候我在这一行中得到一个EXC_BAD_ACCESS
:发布照片Facebook iOS
[_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];
我的视图控制器具有这些代表:
<UIImagePickerControllerDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, MFMailComposeViewControllerDelegate, FBSessionDelegate, FBDialogDelegate, FBRequestDelegate>
编辑:是否有任何插件分享照片轻松了Facebook,G +,以及其他一切容易吗?
大家好, 以为我会与大家在这里分享,我刚刚发布的教程在我的关于如何上传照片博客并使用最新的Facebook SDK发布状态更新。还有一个示例项目需要下载。 看看这里: http://xcodenoobies.blogspot.com/2012/09/how-to-upload-photo-and-update-status.html 谢谢。 – GeneCode 2012-09-07 12:20:10