Get a token for authorization through Facebook?

0 like 0 dislike
8 views
Try to get success token for authentication, not out.
1. Try this:
$token = json_decode(file_get_contents(API_OAUTH_TOKEN_URL . '?client_id=' . CLIENT_ID . '&redirect_uri=' . REDIRECT_URI . '&client_secret=' . CLIENT_SECRET . '&code=' . $_GET['code']),true);

The result:
Warning: file_get_contents(https://graph.facebook.com/oauth/access_token?...
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in login.php on line 14

2. Do this:
$api_host = API_OAUTH_TOKEN_URL; $access_token_parameters = array( 'client_id' => CLIENT_ID, 'client_secret' => CLIENT_SECRET, 'redirect_uri' => REDIRECT_URI, 'code' => $_GET['code'] ); $jResult = $ins->getAccessTokenUrl($api_host, $access_token_parameters); public function getAccessTokenUrl($api_host, $access_token_parameters){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $api_host); curl_setopt($ch, CURLOPT_POST,true); curl_setopt($ch, CURLOPT_POSTFIELDS,$access_token_parameters); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, THIS, false); curl_setopt($ch, CURLOPT_TIMEOUT, 90); $jsonData = json_decode(curl_exec($ch)); if (!$jsonData) { exit('could Not obtain token.'); } curl_close($ch); return $jsonData; }

Nothing happens.

If you go to manual mode, the answer is:
{ "error": { "message": "The request is invalid because the app is configured as a desktop app", "type": "OAuthException", "code": 1, "fbtrace_id": "FhvSAYwHN1M" } }
by | 8 views

2 Answers

0 like 0 dislike
by
0 like 0 dislike
If you have been briskly with code 400 , which means the parameter you gave is not true , and will tell the detailed error message from server facebook.
by

Related questions

0 like 0 dislike
2 answers
asked May 20, 2019 by jenya7771
110,608 questions
257,186 answers
0 comments
28,760 users