I am making and app that you modify images and then you could upload it to Twitter, Facebook, etc… My problem it’s with Facebook. also fbDidLogin never called. I Follow allot of tutorials to this and search allot and try allot of solutions and nothing.
Because i don’t know if the user will export the photo to Facebook I login it only when its necessary I leave the code. I hope someone can help me.
What I need it’s to publish my image that I create into the users wall
//<FBSessionDelegate, FBDialogDelegate, FBRequestDelegate>
- (void)publishFacebook:(UIImage *)img {
[self loginFacebook];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, @"picture", @"Testing...", @"caption",
nil];
[_facebook requestWithGraphPath:@"me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];
NSLog(@"Image posted");
}
- (void)loginFacebook {
if (_facebook == nil) {
_facebook = [[Facebook alloc] initWithAppId:kAppId 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 arrayWithObjects:@"email", @"offline_access", @"publish_stream", nil];
[_facebook authorize:permissions];
[defaults synchronize];
}
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[_facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[_facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
And in my app delegate
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[_viewController facebook] handleOpenURL:url];
}
// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [_viewController.facebook handleOpenURL:url];
}
It go to the Facebook app, and it request all the permissions etc.. and IT said in the console “Image Published” but if I stay in Facebook app without accepting or declining, just stay there it execute the upload image…
If in the Facebook App I accept all the permissions it return to my normal app. The app Delegate methods are return normal values a webpage of Facebook with a really long string.
What could I do?
Thanks
Try this code…
Check out did you put delegate to FBsessionDelegate,FBRequestDelegate in your controller File.Try to run your facebook in your app itself and NOT in SAFARI.To do that check this link. Facebook Implementation within app (without opening in safari or native app)
EDITED:
Changed code with postWall method and added fbDidNotLoginMethod.This is the correct one.