I have an iPhone/iPad app that does some basic photo editing and gives the user the option to upload the finished product to Facebook. The app has more than 100,000 users and the majority seem to have no problem uploading their photos to Facebook. However, there are a handful of users that cannot seem to get their photos to upload no matter what they try. I have worked with them to ensure it is not app permissions or Facebook settings blocking them and cannot find any problem there. So I'm wondering if I am doing something incorrectly with FBConnect that is causing the problem to crop up once in a while. Here is the code:
- (void)initFacebook {
if( self.facebook == nil ) {
Facebook *fb = [[Facebook alloc] init];
self.facebook = fb;
[fb release];
}
if( [self.facebook isSessionValid] ) {
[[NSNotificationCenter defaultCenter] postNotificationName:#"FacebookIsReady"
object:nil
userInfo:nil];
} else {
NSArray *perms = [NSArray arrayWithObjects:#"publish_stream", #"user_likes", nil];
[self.facebook authorize:MY_FB_APP_ID permissions:perms delegate:self];
}
}
-(void)fbDidLogin {
[[NSNotificationCenter defaultCenter] postNotificationName:#"FacebookIsReady"
object:nil
userInfo:nil];
}
// this is in a different class
- (void)facebookIsReady:(NSNotification *)notification {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:self.theImage, #"source", nil];
[appDelegate.facebook requestWithGraphPath:#"/me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:appDelegate];
}
In the FBRequestDelegate the didLoad is always called even when the photo fails to appear in the Facebook profile. So what I'm getting at is the code never seems to fail but the photo doesn't always appear on the Facebook profile.
Is it possible that the app is not able to create a new album on the users profile? I have seen others report this problem before on various groups but have never found an actual solution. Thanks.
You have to include user_photos in your permissions array like this:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"user_photos",
#"publish_stream",
#"user_likes",
nil];
Here is the list of all the permissions: https://developers.facebook.com/docs/reference/api/permissions/
Uploading Photo on Facebook vie Social Framework is much easier .
Pleae check the below link
Fabecook Sharing
Related
I'm using the Parse SDK to implement a Facebook apprequests dialog in my app. For all intents and purposes it just wraps the Facebook SDK, prefixing Facebook methods with PF_.
I use this code to prepare and raise the dialog:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:#"I just challenged you to a game!"], #"message",
[friendIds componentsJoinedByString:#"," ], #"to",
nil];
PF_FBSession *session = [PFFacebookUtils session];
PF_Facebook *facebook = [[PF_Facebook alloc] initWithAppId:session.appID andDelegate:nil];
facebook.accessToken = session.accessToken;
facebook.expirationDate = session.expirationDate;
[facebook dialog:#"apprequests" andParams:params andDelegate:self];
This works well, I'm getting the dialog, I'm able to invite friends to play with the app.
The problem is that the delegate methods are not being called, even though I've set the view controller as a PF_FBDialogDelegate:
#interface ChallengeFriendsViewController : UIViewController <UITableViewDelegate, PF_FBDialogDelegate> {
NSArray *facebookFriends;
NSMutableArray *selectedFriends;
}
These are some of the delegate methods I'm talking about:
- (void)dialog:(PF_FBDialog *)dialog didFailWithError:(NSError *)error {
NSLog(#"Error in Dialog: %#", error);
}
- (void)dialogDidNotCompleteWithUrl:(NSURL *)url {
NSLog(#"Failure on Facebook server side");
}
- (void)dialogCompleteWithUrl:(NSURL *)url {
NSLog(#"Did complete with URL");
[self.navigationController popViewControllerAnimated:YES];
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}
- (void)dialogDidNotComplete:(PF_FBDialog *)dialog {
NSLog(#"Cancelled");
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}
Without these methods being called I'm really not able to handle the sharing in an intuitive way. I'm stumped as to why they wouldn't be called and feel I've tried everything. Any pointers to where I'm going wrong?
In your code you have
PF_Facebook *facebook = [[PF_Facebook alloc] initWithAppId:session.appID andDelegate:nil];
Since you set a nil delegate, I would expect the delegate methods are never called, as you describe.
Could you change this to
PF_Facebook *facebook = [[PF_Facebook alloc] initWithAppId:session.appID andDelegate:self];
That is assuming that you put the delegate methods in the same class.
I finally got around the problem by using the facebook instance provided by PFFacebookUtils. This is deprecated but appears to be the only way to make it call the correct delegate methods at the moment.
Replaced:
PF_Facebook *facebook = [[PF_Facebook alloc] initWithAppId:session.appID andDelegate:nil];
With:
PF_Facebook *facebook = [PFFacebookUtils facebook];
Thanks to JP and Aromal for your input.
I'm trying to use the Facebook iOS "feed" dialog call to allow my app's user to share something on their Facebook wall. When the facebook app is not installed, it attempts to let them authenticate within the app (presumably using a web view). The issue is that this dialog just disappears once they authenticate. I was expecting the web view to return to the "feed" sharing view.
How do I detect that they authenticated so that I can re-open the feed dialog?
I've added fbDidLogin to my app delegate, but it's not being called. (I wasn't sure if this would normally be called or not, but I read several people recommending this.)
SBJSON *jsonWriter = [SBJSON new];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"More Videos",#"name",#"http://www.example.com/",#"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test Caption", #"caption",
#"Test Description", #"description",
#"https://s3.amazonaws.com/example/images/test.png",
#"source",
self.video.blogLink, #"link",
#"01234567890123", #"app_id",
actionLinksStr, #"actions",
nil];
[delegate facebook].sessionDelegate = delegate;
[[delegate facebook] dialog:#"feed" andParams:params andDelegate:self];
It turns out the issue is the same as those reporting that the dialog disappears immediately for them. There is a bug in the Facebook SDK in regards to handling error -999, with the solution described in this comment on SO.
I finally realized I was having the same issue (albeit manifesting slightly differently), when I started listening to the FBDialogDelegate's method:
- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError *)error
The error description referenced the -999 error mentioned above, leading me to the answer. Luckily the code checked into github worked flawlessly. I just had to pull it into the SDK codebase and recompile the .a lib file, then include it into my project.
Did you implemented facebook protocol FBSession in your view controller ?
To detect that user is authenticated you have to call isSessionValid:
if (![[self.fbAppDelegate facebook] isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:#"publish_stream",#"create_event",#"offline_access", nil];
[[self.fbAppDelegate facebook] authorize:permissions];
}
and authorize inApp:
[self authorizeWithFBAppAuth:NO safariAuth:NO];
I want to get profile image of facebook friends. I know I can do this in code by getting id of user and using this link: userID/picture">http://graph.facebook.com/userID/picture. Is there easier way to get profile image directly from facebook sdk?
The Facebook SDK uses the same user ID and path to its graph. So I think it is not easier. But the same.
what about getting the url of the profile picture? then use something like SDWebImage to display the image and cache it to device. or any open source library that can display and cache image just by passing the url to it?
then, get the userIDs of his friends. save them in NSArray. then create a fql.
-(void)getFriendsInfo:(NSArray*)userIDs
{
//prepare param
NSMutableString *paramStr = [[NSMutableString alloc]init];
for (int i = 0; i<[userIDs count]; i++) {
if ([[userIDs objectAtIndex:i] isKindOfClass:[NSDecimalNumber class]]) {
NSString *tempParam = [NSString stringWithString:[[userIDs objectAtIndex:i]stringValue]];
[paramStr appendFormat:#"'%#',", tempParam];
}
}
[paramStr appendFormat:#"%#",#"'9999999999999'"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:#"SELECT uid, name, pic FROM user WHERE uid IN (%#)", tempParam], #"query",
nil];
//in my case, I declared Facebook *facebook; in my app delegate using the latest fb sdk
MyAppDelegate *delegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
[[delegate facebook] requestWithMethodName:#"fql.query"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
handle the data in delegate method
- (void)request:(FBRequest *)request didLoad:(id)result
I am trying to make a post on another user's wall using another user using FBConnect. I am using the embedded method of the iOS Facebook API (that is, I am forcing the browser to appear inside my app, so I am not leaving the application at all). This method works for posting into the wall of the same user, but doesn't work on the wall of another user.
self.facebook = [[[Facebook alloc] initWithAppId:self.appID andDelegate:self] autorelease];
if ([self.facebook isSessionValid]) {
[self proceedToPost];
}else{
NSArray *permissions = [NSArray arrayWithObjects:#"publish_stream", #"email", #"read_stream", #"manage_pages", nil];
[self.facebook authorize:permissions];
}
- (void)proceedToPost
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: #"aName", #"name",
self.appID, #"app_id",
self.title, #"caption",
self.link, #"link",
#"animateURL", #"picture",
nil];
[params setObject:"my-user-profile-id" forKey:#"to"];
[self.facebook dialog:#"feed" andParams:params andDelegate:self];
}
The problem is that authorization is done as expected, but when trying to actually post, I see an error message in the embedded browser "cannot post to user's wall".
Can anyone help me with this?
Did you request the publish_stream permission from the extended permissions?
From the documentation about publish_stream permission:
Enables your app to post content, comments, and likes to a user's
stream and to the streams of the user's friends. With this permission,
you can publish content to a user's feed at any time, without
requiring offline_access. However, please note that Facebook
recommends a user-initiated sharing model.
http://developers.facebook.com/docs/reference/api/permissions/
You can request permissons like this:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"publish_stream",
nil];
[facebook authorize:permissions];
[permissions release];
Thanks for reading.
I went through Facebook iOS SDK Feed Dialog issue after authentication but in vain.
What works:
I created a sample "Hello, World" app using the Facebook iOS Tutorial with the Feed Dialog. This tutorial works fine and I am able to see the post in my feed.
Problem:
When I integrated this code in my app, I don't get to see the Feed Dialog after the authentication when the control reaches back to my app.
Flow of control:
I have a UIImagePickerController showing a camera that takes a picture, then shows UIAlertView to indicate that the image is being uploaded, shows a UIAlertView to display the result returned from server, and then finally shows a UIActionSheet to display the different sharing options (share to Facebook, Twitter, etc.).
When the user hits "Share to Facebook", the following selector gets invoked:
- (void) initFacebook
{
//Init Facebook
facebook = [[Facebook alloc] initWithAppId:#"308136969223987" andDelegate:self];
//Check for access_token
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if([defaults objectForKey:#"FBAccessTokenKey"]
&& [defaults objectForKey:#"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:#"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:#"FBExpirationDateKey"];
}
if(![facebook isSessionValid]) {
[facebook authorize:nil];
}
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, #"app_id",
#"https://developers.facebook.com/docs/reference/dialogs/", #"link",
#"http://fbrell.com/f8.jpg", #"picture",
#"Facebook Dialogs", #"name",
#"Reference Documentation", #"caption",
#"Using Dialogs to interact with users.", #"description",
#"Facebook Dialogs are so easy!", #"message",
nil];
[_facebook dialog:#"feed" andParams:params andDelegate:self];
}
This launches the Facebook app to authenticate, and then opens my app again with the UIImagePickerController but doesn't show the Feed Dialog.
Can someone please help me out?
You have to manually call the method you want again, in your case -(void)initFacebook, in the -(void)fbDidLogin of the FBSessionDelegate.
In addition, to make this more generic, a little trick I did after [facebook authorize:nil]; I set a pending target and selector to store the pending command that needs to be executed after login. Something like this...
id fbPendingTarget;
SEL fbPendingAction;
if (![delegate.facebook isSessionValid]) {
[delegate.facebook authorize:nil]; // Facebook app or Safari login, mustitask
// Save pending actions
delegate.fbPendingTarget = self;
delegate.fbPendingAction = #selector(facebookButtonPressed);
[self retain]; // *** hold on to self if you will release self and is using fbPendingTarget as self
}
and when the delegate fires, it runs your pending action ...
- (void)fbDidLogin {
[self storeAuthData:[facebook accessToken] expiresAt:[facebook expirationDate]];
[self apiFQLIMe]; // request user info
// perform any pending actions after login
if ([fbPendingTarget respondsToSelector:fbPendingAction]) {
[fbPendingTarget performSelector:fbPendingAction];
}
self.fbPendingTarget = nil;
self.fbPendingAction = nil;
[self release]; // *** let go of self after we finished everything
}
This help executing any pending actions you need after login. And don't forget to clear them after executing or login failed.
-(void)fbDidNotLogin:(BOOL)cancelled {
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:#"Cannot Connect"
message:#"There was an error while connecting to Facebook. Please try Again."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil] autorelease];
[alertView show];
self.fbPendingTarget = nil;
self.fbPendingAction = nil;
[self release]; // *** let go of self after we finished everything
}
Hope this helps :)
Edit: I find it better to set fbPendingTarget to some object that exists throughout the app lifetime (like appDelegate) rather than setting to self. This is because in many cases your self is a view that will be released right after the user sends a post to Facebook. Sending a message to a released object will crash your app.
A dirty way to get around this is to explicitly use [self retain] before sending and then [self release] in your fbPendingAction. But that would retain everything else that should be released in self by that time. I just find it easier to set to appDelegate since most action you will do is just displaying an alert anyway. I'll edit the code just for safety sake.