i am unable to post to Facebook using Facebook ios sdk. i am receiving the following error.
"This app does not have permission to do this. to change permissions to do this. To change permissions, try logging into the app again."
- (void) performPublishAction:(void (^)(void)) action {
// we defer request for permission to post to the moment of post, then we check for the permission
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound) {
// if we don't already have the permission, then we request it now
[FBSession.activeSession requestNewPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
action();
} else if (error.fberrorCategory != FBErrorCategoryUserCancelled){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Permission denied"
message:#"Unable to get permission to post"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
} else {
action();
}
}
i am using Facebook ios sample from git-hub for testing.i can successfully post to Facebook if i use some old app create on Facebook.i have created the app as described by the Facebook docs.
read the facebook document v2.0 carefully, i do have similar problem.
If your app asks for more than public_profile, email and user_friends, then it will have to be reviewed by Facebook before it can be made available to the general public. Please see our documentation on reviews for more information.
You have to register your app to Facebook at https://developers.facebook.com. Make sure to enter your app's bundle id exactly as it is in Xcode.
Related
To request facebook publish_actions permission during login in android I do
loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setPublishPermissions(“publish_actions”);
loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
#Override
public void onUserInfoFetched(GraphUser user) {
FacebookOptInFragment.this.user = user;
updateUI();
}
});
That’s all I need to do and I am done. User will first login and then get prompted to grant publishing permission. How do I do the exact same thing in iOS?
Note that I just now downloaded the Facebook SDK, which means I have the latest and greatest (in case that is relevant).
Some documentation first
Requesting publishing permissions with publish_actions during login
creates a second step in the login UI. So you should request minimum
read permissions during login then request any additional or publish
permissions when someone actually needs them. To optimize your
permission requests, see Optimizing Permissions.
So If all you need is to authorize your iOS app and grant publish_actions permission and if you really want integrate with iOS Facebook account, you have to ask for reading permission before you ask for the publishing permission. See the Request at Login portion of the page link above for getting read permissions.
Then you can request additional permissions for publish_actions like
// Request publish_actions
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
__block NSString *alertText;
__block NSString *alertTitle;
if (!error) {
if ([FBSession.activeSession.permissions
indexOfObject:#"publish_actions"] == NSNotFound){
// Permission not granted, tell the user we will not publish
alertTitle = #"Permission not granted";
alertText = #"Your action will not be published to Facebook.";
[[[UIAlertView alloc] initWithTitle:alertTitle
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
} else {
// Permission granted, publish the OG story
[self publishStory];
}
} else {
// There was an error, handle it
// See https://developers.facebook.com/docs/ios/errors/
}
}];
Check this portion of the docs for permission management as well
I am trying to get all the events that user has created for that i am trying to request permission for accessing the user_events.
However thus far facebook is not asking user for permission to access events. I have checked the test user app permission profile and my app is only getting profile info but not events settings.
The facebook sdk i am using is 3.19
if ([FBSession.activeSession.permissions indexOfObject:#"user_events"]==NSNotFound) {
[FBSession.activeSession requestNewReadPermissions:#[#"user_events"] completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
action();
}
else if (error.fberrorCategory != FBErrorCategoryUserCancelled)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Permission denied"
message:#"Unable to get permission to post"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
}
else
{
action();
}
user_events needs to get approved by Facebook before it works with any user, else it will only work for users with a role in your app: https://developers.facebook.com/docs/apps/review/login
I am working on ios application where I have to implement facebook publish/share feature. what I have done for sharing is
1: if user is not logged in, I am checking with this
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded||FBSession.activeSession.state == FBSessionStateOpen) {
//NSLog(#"Open");
//Set already opened session to FBSession
[FBSession setActiveSession:appDelegate.session];
//if user logged in already, perform sharing on fb
[self sharePostOnFb];
}else{
//if user is not logged in
[self openFbLogin];
}
-(void)openFbLogin
{
[FBSession openActiveSessionWithReadPermissions:#[#"public_profile", #"email",#"publish_actions"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
// Retrieve the app delegate
//AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
// Call the app delegate's sessionStateChanged:state:error method to handle session state changes
//[appDelegate sessionStateChanged:session state:state error:error];
if (state == FBSessionStateOpen) {
NSLog(#"opened");
[self sharePostOnFb];
}
}];
}
-(void)sharePostOnFb
{
NSString *strBznsName = [[[Global sharedInstance]getBznsInfo] objectForKey:#"name"];
NSString *strUserReceive = [NSString stringWithFormat:#"%# %# received %#.",[[[Global sharedInstance]getUserData] objectForKey:#"firstname"],[[[Global sharedInstance]getUserData] objectForKey:#"lastname"],dataStampDeal.strDealTerms];
NSString *urlLogoBkString= #URL_BZNSImgPath;
NSURL *urlLogoBkImage = [NSURL URLWithString:[NSString stringWithFormat:#"%#/%#",urlLogoBkString,[[[Global sharedInstance]getBznsInfo] objectForKey:#"logo" ]]];
NSString *StrUrl = [NSString stringWithFormat:#"%#",urlLogoBkImage];
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
strBznsName, #"name",
#"Powered By Anyloyalty", #"caption",
strUserReceive, #"description",
StrUrl, #"picture",
nil];
// Make the request
[FBRequestConnection startWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Link posted successfully to Facebook
NSLog(#"result: %#", result);
strFbPostId = [result valueForKey:#"id"];
NSLog(#"post id: %#", strFbPostId);
//[self WebServiceHandler:NO];
//[appDelegate startanimation];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#", error.description );
NSDictionary *errorInformation = [[[[error userInfo] objectForKey:#"com.facebook.sdk:ParsedJSONResponseKey"]
objectForKey:#"body"]
objectForKey:#"error"];
//NSLog(#"%#", errorInformation );
//__block NSString *alertText = #"Your action will not be published to Facebook.";
__block NSString *alertText = [errorInformation valueForKey:#"message"];
[[[UIAlertView alloc] initWithTitle:#"error"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
}
}];
}
facebook login (-(void)openFbLogin()) is opening web dialog. After successfully logged in. I am sharing post ( -(void)sharePostOnFb()) on fb and I am getting error
"(#200) The user hasn't authorized the application to perform this action"
For publishing/sharing I have to get approval for "publish_actions" permission from FB. I have submitted my application to FB app developer center. I am getting this message.
"Your app must not use a Facebook Web Dialog. Utilize our native Facebook Login SDK for iOS, so that users do not need to login twice."
so Now I want to "what is native Facebook Login SDK for iOS"? and how can I integrate that with my app?
The native Facebook login is nothing but using the iOS FB framework and create login using that. It is clearly mentioned on the developers.facebook.com how to login using there framework. You can also see the samples provided by them for login.
What this actually does is that , it check if the user has a Facebook application installed in the device and is user logged in to the Facebook app. If user is already logged in then user won't be asked to log in again. If user isn't logged in then they will be redirected to safari where they will have to log in to FB.
Its quite simple to integrate. Its well explained.
Facebook clearly says,
All iOS and Android apps should use their SDK's for iOS and Android for requesting permissions. Other apps should use their JavaScript for requesting permissions wherever possible.
Native applications on iOS and Android especially should use their SDK flows as they are optimized and work robustly across various types of devices without any manual adjustment.
In particular, their native SDKs let people who are already logged in to their Facebook app grant permissions without having to log in to their Facebook accounts again. This will result in far better conversion than not using our SDK and rendering our login dialogs inside web views embedded within your native app since the web view will not have any Facebook session data initially and will require people to login to their Facebook account.
Please note: if you are using Apple's Social framework, you may continue to do so, but ensure that if the user is not using the iOS integration, that your app falls back to the Facebook SDK for iOS. This can create more work than necessary, though, so we highly recommend using their SDK instead.
Here are the SDK implementation details:Facebook Login SDK for iOS
So I ran into something I can't explain. I've got two devices
Iphone 4
Running iOS 7.0.6. With Native Facebook app installed. But not logged in
iPhone 5s
Running iOS 7.1. With Native Facebook app installed and user logged in.
When I try to access the profile data. It's running smoothly on an iPhone 5s, but breaks after permission dialog on the iPhone 4. So the user allows for sharing specific info to the app. Then at a next screen I'm confronted with a general error message (in Facebook app), saying it was unable to process.
This is how I got it working so far.
Facebook permission
// Make request facebook
[FBSession openActiveSessionWithReadPermissions:[NSArray arrayWithObjects:#"email", nil]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
{
if (error)
{
NSLog(#"Facebook Errors: %#", error.description);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook unable to connect"
message:#"Facebook error message here"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
if (FBSession.activeSession.isOpen)
{
// Login via Facebook succeeded.
// We have a session.
[self facebookLoginRequestForMe:onCompletion withScore:score];
}
else
{
// We could not login to Facebook.
if (onCompletion)
{
onCompletion(false);
}
}
}];
Trying to access profile
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser>* fbUser, NSError *fbError)
{
NSString* fbUserEmail = [fbUser objectForKey:#"email"];
bool fbSuccess = (!fbError && fbUserEmail && fbUserEmail.length > 0);
if (fbSuccess)
{
NSString* facebookImageURL = [NSString stringWithFormat:#"http://graph.facebook.com/%#/picture?type=large", fbUser.id];
NSLog(#"User name: %#", fbUser.name);
NSLog(#"User email: %#", fbUserEmail);
NSLog(#"usr_id: %#", fbUser.id);
NSLog(#"usr_first_name: %#", fbUser.first_name);
NSLog(#"usr_middle_name: %#", fbUser.middle_name);
NSLog(#"usr_last_name: %#", fbUser.last_name);
NSLog(#"usr_username: %#", fbUser.username);
NSLog(#"usr_birthday: %#", fbUser.birthday);
NSLog(#"avatar url: %#", facebookImageURL);
}
else if (onCompletion)
{
onCompletion(false);
//TODO: present custom error
}
Am I missing some special callback data I need to present?
Thanks!
Don't believe this! But got it resolved
Scenario: if you have not signed in on Facebook natively (settings -> Facebook -> login credentials here), your device will use the Facebook app to validate the authorization for profile data via Facebook.
This will not work if you have not put the Facebook app in Live mode.
Go to developer.facebook.com
Go to apps
Select Status / review
Do you want to make this app and all its live features available to the general public? YES
You're done!
I am trying to login to a facebook account without the admin and test user I have been testing with. This is using the Parse.com framework facebook login utility. I get the error:
NSLocalizedDescription=User is not a test user owned by the application
My code to authenticate with facebook is hitting this condition:
[PFFacebookUtils logInWithPermissions:nil block:^(PFUser *user, NSError *error) {
if (!user) {
NSLog(#"User doesn't exist");
NSLog(#"%#", error);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
I have set my app to: "Live and Available to All Users" in the facebook developer app dashboard.
Why am I receiving this error and how do I allow my app to be logged in by any user with a facebook account?
The problem was that I was already logged in in the simulator with a non valid account.