0

这是我的代码:

<?
session_start();

require_once($_SERVER['DOCUMENT_ROOT'].'/admin/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/admin/fonctions.php');

include '../api/facebook.php';
include '../api/xhttp.php';


  $config = array();
  $config['appId'] = '35455XXXXXXX207';
  $config['secret'] = '6006855f3aXXXXXXXXX9bce45a426';
  $config['fileUpload'] = false; // optional

  $facebook = new Facebook($config);


$args = array(
    'message'   => 'Hello from my App!',
    'link'      => 'http://www.masteringapi.com/',
    'caption'   => 'Visit MasteringAPI.com For Facebook API Tutorials!',
    'access_token'  => $access_token
);

$retour_login = json_decode(stripslashes($_GET['session']), true);
$uid = $retour_login['uid'];
$access_token = $retour_login['access_token'];

$post_id = $facebook->api("/me/feed", "post", $args);

?>

但它返回:未捕获的 OAuthException:必须使用活动访问令牌来查询有关当前用户的信息。有任何想法吗 ?

谢谢!


这是我的新代码:

<?


  $config = array();
  $config['appId'] = '3545XXXXXXX6207';
  $config['secret'] = '60068XXXXXXXXXXXe45a426';


  $facebook = new Facebook($config);


$retour_login = json_decode(stripslashes($_GET['session']), true);
$uid = $retour_login['uid'];
$access_token = $retour_login['access_token'];


$me = null;
// Session based API call.
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}

if(!isset($_GET['session'])) {
    $params = array(
    'locale' => 'fr_FR',
    'display' => 'popup', 
    'req_perms' => 'email,user_about_me,user_birthday,user_location',
    'ext_perms' => 'publish_stream,share_item,manage_pages'
    );
    header("Location: ".$facebook->getLoginUrl($params));
}



        $args = array(
                'message'   => "XXXX",
                'link'      => 'XXXX',
                'name'      => 'XXXX',
                'picture'   => 'XXXX',
                "caption"=> "lien.com",
                      "type"=> "link");

        $post_id = $facebook->api("/me/links", "post", $args);

?>

这次我收到此错误:OAuthException:(#282)需要扩展权限:share_item throw

有任何想法吗 ?

谢谢!

4

2 回答 2

0

您没有将访问令牌传递给它。

查看 getAccessToken()。

于 2012-05-08T22:26:26.917 回答
0

从您的代码示例看来,您正在尝试使用变量 $access_token 来创建您的 $args 数组,然后再定义 $access_token 变量。我会切换变量定义的顺序:

$retour_login = json_decode(stripslashes($_GET['session']), true);
$uid = $retour_login['uid'];
$access_token = $retour_login['access_token'];

$args = array(
'message'   => 'Hello from my App!',
'link'      => 'http://www.masteringapi.com/',
'caption'   => 'Visit MasteringAPI.com For Facebook API Tutorials!',
'access_token'  => $access_token
);

这是假设 $retour_login['access_token'] 包含有效的 Facebook 访问令牌。否则,您将需要使用 Facebook SDK 获取当前用户的访问令牌:

$access_token = $facebook->getAccessToken();
于 2012-05-09T02:10:20.083 回答