Unable to get access_token when user uses "visit web site" button from Facebook's app center
facebook-apps, oauth
Solution
From the Authenticated Referrals part of the docs (the App centre counts as an authenticated referral)
See A special consideration when using the Query String setting:
If you would like to use the server-side authentication flow it is important to make sure you are passing the redirect_uri parameter correctly when exchanging your code for an access token. You should set your redirect_uri parameter to the click-through URL to your site without the code parameter. In most cases the URL will look something like:
http://www.example.com/?fb_source=search&code=CODE_HERE Once you strip the code parameter it will become:
http://www.example.com/?fb_source=search which is the value that should be set in redirect_uri. Please make sure that this logic is dynamic as the query parameters appended to your click-through URL may be subject to change.
Using your example from above, this means your `redirect_uri` parameter should be `http://www.myappsite.it/?fb_source=appcenter&fb_appcenter=1`
Problem
I'm trying to promote my app using app center but from the Web preview I can't visit the web site. The link that is called is http://www.myappsite.it/?fb_source=appcenter&fb_appcenter=1&code=a_long_string From the index.php of myappsite I use this peace of php code to get the user coming from facebook ``` $code = $_REQUEST["code"]; if($_REQUEST['state'] == $_SESSION['state'] && !$user && strlen($code) > 0) { $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $appId . "&redirect_uri=" . urlencode("http://www.myappsite.it/") . "&client_secret=" . $secret . "&code=" . $code; $response = @file_get_contents($token_url); $params = null; parse_str($response, $params); $graph_url = "https://graph.facebook.com/me?access_token=" . $params['access_token']; $user = json_decode(file_get_contents($graph_url)); echo("Hello " . $user->name); } ``` but $params['access_token'] is empty because the $token_url returns ``` { "error": { "message": "Error validating verification code.", "type": "OAuthException", "code": 100 } } ``` how can I get the user logged in from tha app center preview web page?