1
How to post to a facebook page through PHP?
I’m trying to:
require 'facebook_php_sdk/Facebook.php';
// ATENCAO, configurar os parametros abaixo
$APP_ID = "12345678"; // id da app
$SECRET = "***************************"; // secret da app
$PERMS = "publish_actions,manage_pages";
// objeto do facebook
$facebook = new Facebook(array(
'appId' => $APP_ID,
'secret' => $SECRET,
));
// monta URL atual
$my_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
// obtem CODE da autenticacao OAUTH
$code = $_REQUEST['code'];
if(empty($code)) {
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $APP_ID . "&redirect_uri=" . urlencode($my_url)
. "&scope=$PERMS";
header("Location: $dialog_url");
exit;
}
// com o CODE vamos gerar a URL para obter o access token do usuario
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $APP_ID . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $SECRET . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
// printando o access token e quando ele ira expirar
echo "Access Token: ";
echo $params['access_token'];
echo "<br />";
if (!empty($params["expires"])) {
echo "Irá expirar em: " . date("d/m/Y H:i:s", time() + $params["expires"]);
}
I just keep getting the bug:
Parse error: syntax error, unexpected T_STRING in /home/igosp794/public_html/modulo/administrativo/facebook_php_sdk/Facebook.php on line 24
On line 24 we have:
namespace Facebook
What’s on the line 24 of the file /home/igosp794/public_html/module/administrative/facebook_php_sdk/Facebook.php ?
– Juven_v
Just: namespace Facebook;
– sNniffer
It may be that the version of php you are using does not support the use of namespace. See if your php version is higher than 5.3.
– Juven_v
Oops buddy, forgive me the delay, I updated the php of the server, I’m with the error
Fatal error: Class 'Facebook' not found in face.php on line 20
, line 20 has:$facebook = new Facebook(array(
. In require_once either with autoload.php or Facebook.php, the error is the same.– sNniffer