Post Page Facebook SDK php

1

How to publish to a facebook page through PHP?

I'm trying:

    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&aacute; expirar em: " . date("d/m/Y H:i:s", time() + $params["expires"]);
}

I just constantly get the error:

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
    
asked by anonymous 18.05.2016 / 21:23

1 answer

0

As far as I can tell you're not using facebook sdk autoload. Even solving the error described by you is unlikely to work. The only require_once you should do is the facebook sdk autoload.php file. It will automatically include the classes needed to run the application. All of this assuming you are using the latest version of sdk.

In this link you can see a tutorial on how to install the correct facebook sdk.

    
19.05.2016 / 18:26