[php] Redirecting to authentication dialog - "An error occurred. Please try again later"

Why does it always happen to me?

This happens after my application verify for user user login and redirect user to the authentication page:

https://www.facebook.com/dialog/oauth?client_id=XXX&redirect_uri=http%3A%2F%2Fexample.com%2Fmyappname%2F&state=YYYYYY&scope=offline_access%2Cpublish_actions

But instead of showing the authorization page, Facebook shows an error page with

An error occurred. Please try again later.

Is there any configuration I have to do before try to authenticate my users?

All is done with PHP using the PHP-SDK classes.

This question is related to php facebook facebook-graph-api

The answer is


In my case, there was an age issue with the account being used with the app.

If the FB app has alcoholic content then FB users who are younger than about 21 will throw an error when trying to authorize with it.


According to OAUTH Dialog documentation:

*redirect_uri: The URL to redirect to after the user clicks a button in the dialog. The URL you specify must be a URL of with the same Base Domain as specified in your app's settings, a Canvas URL of the form https://apps.facebook.com/YOUR_APP_NAMESPACE ...*

I am constructing oauth links dynamically to ask a user for additional permissions if needed and I realized, that even if you are redirecting to https://apps.facebook.com/YOUR_APP_NAMESPACE you have to have the App Domain and Website settings set in your application administration. I set domain to facebook.com and Website to facebooks root url.

Now my oauth dialog link works fine - even in sandbox mode.


Check your appid and make sure you have updated your Site URL Mobile Site URL in https://developers.facebook.com/


Solution for me is to set option 'Authenticated Referrals' to enabled. Its realy fixed after that.

Fix permissions error


The reason in my case was completely different. I was trying to open a Feed dialog automatically after page load. And 9 times of 10 it displayed this error. First, I added show_error: true parameter as suggested by @Peter Roome, but it didn't help, displaying 104: Invalid signature, not descriptive at all.

Then I figured out the reason. The code was in $(document).ready jQuery function. And it seems that some facebook stuff had not yet been loaded at the point the code was to be executed. I moved the code to $(window).load block (which is executed after all page content is loaded), and the problem has been solved.


I had the same problem; it turned out FB requires a string appID and not an int...

//DOESNT WORK:
$facebook = new Facebook(array(
  'appId'  => 147XXXXXXXXXXX,
  'secret' => 'XXXXXXXXXXXXXX',
));

// WORKS:
$facebook = new Facebook(array(
  'appId'  => '147XXXXXXXXXXX',
  'secret' => 'XXXXXXXXXXXXXX',
));

Answer for 2015

Sandbox mode is gone.

Proceed to My Apps -> Your App -> Status & Review and change the slider to yes for:

Do you want to make this app and all its live features available to the general public?

enter image description here


Also had a problem with wrong redirect link: I had a link starting with "https://apps.facebook.com?myapplication".... but after authorization the redirection would bring me to "apps.facebook.com/Myapplication" and consequently I would get a message described above:"Error occured. Try back later." since "apps.facebook.com"... means "http://apps.facebook.com/Myapp" and not "HTTPS://apps.facebook.com/,..."

The solution: went to my application settings in facebook developers section. Clicked 'Edit'. In the left-side Menu selected "Permissions" (by default the Menu is set to Basic) and in the newly opened set of setting changed my "Auth Token Parameter" from "Query string" to "URL Fragment".

It worked! After authorization is finished the users are taken to "https://apps.facebook.com/myapp..."


I just encountered this problem myself. I'm developing an app internally, so my host is 'localhost'. It wasn't obvious how to set 'localhost' up in the app configuration. If you want to develop locally, set up your app by following these steps:

  1. Go to the place where you manage your Facebook app. Specifically, you want to be in "Basic" under the "Settings" menu.
  2. Add 'localhost' to "App Domain".
  3. Under "Select how your app integrates with Facebook", select "Website", and enter "http://localhost/".

Save and wait a couple of minutes for the information to propagate, although it worked right away for me.


Settings > advanced > security > valid oauth redirect URI

enter image description here


Another possible mistake, if you directly copied the code from Facebook SDK example then you may get the same error despite of having everything correct. http://developers.facebook.com/docs/reference/php/

This is because in their example they have used backquotes instead of single quotes for the key of the array. The correct code is as follows.

require_once("facebook.php");

$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';
$config['fileUpload'] = false; // optional

$facebook = new Facebook($config);

When working with Dialogues, Facebook provide a 'show_error' attribute that defaults to no but can be set to true in a Development environment and is really helpful for debugging purposes.

show_error - If this is set to true, the error code and error description will be displayed in the event of an error.

Instructions of it's use can be found in the Facebook Docs.

I'd been debugging "An Error occurred. Please try later." dialogue before i found this attribute in the docs. Once i started using it, i could see the following message too:

API Error Code: 191

API Error Description: The specified URL is not owned by the application

Error Message: redirect_uri is not owned by the application.


The issue resolved after I updated the 'appID' and 'secret' and then pushed the change back to heroku (i.e. - 'git push heroku master')

The key is not to forget to push the changes back to heroku master. Very easy to overlook if you're use to testing on localhost.

Hope this helps.


I had the same problem, and fix it by adding param &display=touch to url

try, it may helps


This was happening to me also but all the api keys, secrets and stuff were correct. What I found is that my app was running in sandbox mode. Go to your app settings in https://developers.facebook.com/ click the advanced settings tab and check to see if your app is in sandbox mode. If it is disable it and try again. Let us know if it works.


If you're the app developer, you may see a more specific error message, but generally that message means one of two things:

  1. Your server returned a HTTP error code (usually 5xx)
  2. You tried to send the user, after login, to a URL not allowed by your app configuration (though as an Admin of the app, you should see a more specific error message and Facebook error code in this case)

Came here with a similar problem and, yes, my Sandbox was enabled. I disabled it and, voila, the login problem went away. I must warn that this problem does not affect developers and website administrators as Facebook allows those users to see the app. For this reason, I couldn't even believe that users complained about not being able to login, as I was able to login with no problems at all.


I had this error because I was using redirect_url as a parameter instead of redirect_uri.

The Server-Side Authentication doc page says to use redirect_url:

https://www.facebook.com/dialog/oauth?
    client_id=YOUR_APP_ID
   &redirect_url=YOUR_REDIRECT_URI
   &scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
   &state=SOME_ARBITRARY_BUT_UNIQUE_STRING

But this is incorrect. The OAuth Dialog doc says to use redirect_uri instead, which works, so I'm assuming that you can only use one and not the other:

https://www.facebook.com/dialog/oauth/?
    client_id=YOUR_APP_ID
    &redirect_uri=YOUR_REDIRECT_URL
    &state=YOUR_STATE_VALUE
    &scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES

If your all code is working properly then to remove such type of error go to Facebook Developers Apps and disable sandbox mode.


I had put the restriction on the app that only United States residence could use the app. I was working from Canada at the time this error message appeared. After removing the restriction everything worked.


For me this happened because the "test user" I created was part of a separate app. I created a test user for THIS app, and it started working fine.

Stupid on my part I know, but this could save someone else some trouble.


I have had the same problem as you.

From the Facebook Developers Apps page, make sure that the Sandbox Mode is disabled.

enter image description here


There is no possibility to solve this type of error. So Its better to use your custom dialog same like shown in facebook and post message again & again without login. Even though you remove your app from facebook, you can ask for login and post message successfully.


You need to specify http:// in your REDIRECT URI.


For me the issue was that the url of the app didn't completely match the url I was running it on (i.e different directories, same domain)


I had the same problem and the root cause was different:

I was logged in as a Test User of a different application. Therefore I wasn't able to authorize an app that's not the one where the Test User was created for.

When I logged out and logged in as a regular user or a Test User for the app I tried to authorize, everything was OK.


Make sure your app is configured to use the appropriate URL & domain of your site. That may be it.


I know u may got the answer but this is for those who are still going down the thread for getting the solution.

U can try all the above solutions but just remember that delete the Previous app from the device or simulator before checking another solution.

I tried all solutions but getting no response as i was not deleting the previous app, only cleaning the build does not satisfy the condition.Hope it helps someone. :)


I had this exact problem on a Page Tab app and for the life of me couldn't work out what the problem was. It worked on my test page but as soon as I made it live it wouldn't work. I found in the end that I fixed the problem by putting the actual URL to the Page Tab (i.e. http://www.facebook.com/<"page_name">/app_<"app_id">) into "Site URL" under "Website". This doesn't make any sense. But it worked :-)


I had tried all the answers mentioned here. But it didn't work. I had to delete and create again. I am guessing it was due to new the "Authenticated Referral". If you have added Open Graph objects which are not approved, it might give you an error.


For me the problem was that the Facebook users I was using to test the app did not have its email address confirmed by Facebook.

My client had set up 2 fake accounts on Facebook and told me that they were not working. But he forgot to confirm the email addresses of those accounts (the emails Facebook sent went to his spam folder and he didn't notice).

Took me hours to find this, so I hope it helps somebody.

Cheers!


I was getting this error because I was starting from http://mysite.com, but had specified http://WWW.mysite.com in my Facebook settings - the www mattered... I ended up solving by using .httpaccess to always kill the "www", and pointing FB to http://mysite.com

worst. subdomain. ever. :u)


I faced the same problem and reason was that my app was not live and publicly available.

I added my email id in contact email under setting tabs and make my app live(which previously was disabled to make live).

After making my app live its showing sharing dialogue with proper image, title and description with my app name in bottom.


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to facebook

I am receiving warning in Facebook Application using PHP SDK React-Native: Application has not been registered error Can't Load URL: The domain of this URL isn't included in the app's domains Facebook OAuth "The domain of this URL isn't included in the app's domain" Facebook login message: "URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings." Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView` Open Facebook Page in Facebook App (if installed) on Android App not setup: This app is still in development mode IOS - How to segue programmatically using swift Get ALL User Friends Using Facebook Graph API - Android

Examples related to facebook-graph-api

"Uncaught (in promise) undefined" error when using with=location in Facebook Graph API query Facebook OAuth "The domain of this URL isn't included in the app's domain" Facebook login message: "URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings." Facebook Graph API v2.0+ - /me/friends returns empty, or only friends who also use my application Creating a Facebook share button with customized url, title and image Facebook API "This app is in development mode" The developers of this app have not set up this app properly for Facebook Login? New og:image size for Facebook share? facebook: permanent Page Access Token? How to programmatically log out from Facebook SDK 3.0 without using Facebook login/logout button?