Reputation: 1049
I'm trying to upload a photo to Facebook. I read a lot of tutorials and examples and still can't get it to work. Many times I get an EXC_BAD_ACCESS
in this line:
[_facebook requestWithGraphPath:@"me/photos"
andParams:photosParams
andHttpMethod:@"POST"
andDelegate:self];
Other times nothing appears. I want the user to login only when they click on "share image" in Facebook. Thats why I didn't put the delegate in the appDelegate
. Below is my code:
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];
My ViewController has these delegates:
<UIImagePickerControllerDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate, MFMailComposeViewControllerDelegate, FBSessionDelegate, FBDialogDelegate, FBRequestDelegate>
Edit: Are there any plugins to share photos easily in Facebook, G+, and everything else easily?
Upvotes: 1
Views: 1225
Reputation: 9157
Instead of using the graph why don't you try:
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 .....
Upvotes: 2