Answer the question
In order to leave comments, you need to log in
Getting a token for authorization through facebook?
I try to get a success token for authorization, it doesn't work.
1. I try like 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);
$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, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
$jsonData = json_decode(curl_exec($ch));
if (!$jsonData) {
exit('Не получилось получить токен.');
}
curl_close($ch);
return $jsonData;
}
{
"error": {
"message": "The request is invalid because the app is configured as a desktop app",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "FhvSAYwHN1M"
}
}
Answer the question
In order to leave comments, you need to log in
You don't have to make homemade gardens when Facebook already has a ready-made PHP-SDK.
See
https://developers.facebook.com/docs/reference/php
https://developers.facebook.com/docs/php/howto/exa...
getjump.github.io/en-php-the-right -way/#composer_%...
If you received an error with code 400, then you passed some parameter incorrectly, which will be indicated by a detailed error message from the facebook server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question