V
V
Vic Shostak2017-07-26 12:47:49
PHP
Vic Shostak, 2017-07-26 12:47:49

Why does the Facebook API key flies all the time to send a message from the site to the group wall?

Good day.
There is a website (admin panel, PHP), the operator composes a post, clicks on a button, and this post goes to the community page on Facebook (and to other social networks in the same way, but there are no problems there).
The problem is that for some reason, once a week (or less), my Facebook API key flies (from the Graph API Explorer that I get) and I have to go to https://developers.facebook.com/tools/explorer to choose desired group, select a group token, and generate an access token again.
I use the official PHP lib from Facebook, and here is the content of the file that actually makes the request:

header("Access-Control-Allow-Origin: *");
require_once 'src/autoload.php';

$app_id = "<APP ID>";
$app_secret = "<SECRET KEY>";
$group_id = "<GROUP ID>";
$token = "<TOKEN ИЗ TOOLS EXPLORER>";

$fb = new Facebook\Facebook([
    'app_id'  => $app_id,
    'app_secret' => $app_secret,
    'default_graph_version' => 'v2.10',
]);

$linkData = [
  'message' => $_POST['msg']
];

try {
  $response = $fb->post("/{$group_id}/feed", $linkData, $token);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

$graphNode = $response->getGraphNode();

It's just not clear why the token works for some limited amount of time and then (even without any error) stops? It should not be the same, Facebook is the same .. Help, please, who had this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2017-07-26
@Sanasol

select the desired group, select the group token, and generate an access token again.

it is like a test token, and it is not eternal.
You need to get your worker through scripts, and make it eternal.
https://developers.facebook.com/docs/php/howto/exa...
getLongLivedAccessToken

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question