For several months I have been trying to obtain the list of conversations from a page in the following way:
https://graph.facebook.com/v17.0/{page_id}?fields=conversations&access_token=
But I always get the same error: "An unexpected error has occurred. Please try your request again later.", "code: 2.
The code I currently have, which uses the Facebook SDK for PHP, is as follows:
<?php
// Define las variables de entorno.
$clientID = "clientID";
$clientSecret = "clientSECRET";
$redirectUri = "https://meta.dev/msg.php";
$pageID = "PAGE ID";
$params = [
'config_id' => 'xxx',
'response_type' => 'code'
];
$permissions = [
'pages_show_list',
'pages_messaging',
'pages_read_engagement',
'business_management',
];
require_once __DIR__ . '/vendor/autoload.php';
// Crea un nuevo objeto de cliente de Meta.
$client = new \Facebook\Facebook([
'app_id' => $clientID,
'app_secret' => $clientSecret,
'default_graph_version' => 'v17.0',
]);
$oauthClient = $client->getOAuth2Client();
$state = base64_encode( openssl_random_pseudo_bytes(32));
// Espera a que el usuario acepte o rechace el acceso.
if (isset($_GET['code'])) {
// Valida el código de autorización.
$access_token = $oauthClient->getAccessTokenFromCode($_GET['code'], $redirectUri);
$client->setDefaultAccessToken( $access_token );
setcookie('fb_at', $access_token, time()+2592000);
header('Location: ' . $redirectUri);
} else {
if (isset($_COOKIE['fb_at'])) {
// Obtén el Access Token de la página.
if (!isset($_COOKIE['fb_at_page'])) {
$me = $client->get('me/accounts', $_COOKIE['fb_at'])->getDecodedBody();
var_dump($me);
setcookie('fb_at_page', $me['data'][0]['access_token'], time()+2592000);
}
// Obtén las conversaciones de la página.
$conversations = $client->get($pageID.'?fields=conversations',$_COOKIE['fb_at_page'])->getDecodedBody();
var_dump($conversations);
} else {
// Inicia el flujo de autorización.
$auth_url = $oauthClient->getAuthorizationUrl(
$redirectUri,
$state,
$permissions,
$params
);
// Redirigir al usuario al flujo de autorización.
header('Location: ' . $auth_url);
}
}
The access_token code I use is the one on the page. The permissions I am using to generate the primary access token are as follows:
pages_show_list business Administration messaging_pages pages_reading_participation
The code was working fine and returned the conversation list in June, but it stopped working with Meta API updates.
I've tried uploading my code as-is in production to submit the app for review, but I can't even record the screen to complete the review due to the error mentioned above.
In both developer mode and production mode, the same error appears.
Any idea what the error could be?
I tried running the code using various permissions to create the access token, I created new test pages with different Facebook accounts to rule out possible configuration problems, but the vast majority of answers I have found in this regard are the result of executing the Graph API The error could be due to Meta, but I'm surprised that it hasn't been solved for quite some time.