-2
require ('facebook.php');

define('FACEBOOK_APP_ID',"My_ID");
define('FACEBOOK_SECRET',"My_Secret");
define('REDIRECT_URI',"My_Website");
define('PERMISSIONS_REQUIRED', "publish_stream");
$facebook = new Facebook(array(
    'appId' => FACEBOOK_APP_ID,
    'secret' => FACEBOOK_SECRET,
    'cookie' => true
));
    $access_token = $facebook->getAccessToken();

    $query = mysql_query("SELECT `title` FROM `tentego_img` WHERE `id` = ".intval($_GET['id'])."");
    $r = mysql_fetch_array($query);
    $link = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

    $facebook->api('/me/feed', 'POST',
                                    array(
                                      'link' => $link,
                                      'message' => $r[0]
                                 ));

错误:致命错误:未捕获 OAuthException:必须使用活动访问令牌来查询有关当前用户的信息。

请帮忙。

4

1 回答 1

1

试试getAccessTokenFromCode($_GET['code'],REDIRECT_URI)吧,它应该可以工作。这个对我有用。您修改后的代码:

require ('facebook.php');

define('FACEBOOK_APP_ID',"My_ID");
define('FACEBOOK_SECRET',"My_Secret");
define('REDIRECT_URI',"My_Website");
define('PERMISSIONS_REQUIRED', "publish_stream");
$facebook = new Facebook(array(
    'appId' => FACEBOOK_APP_ID,
    'secret' => FACEBOOK_SECRET,
    'cookie' => true
));
if(isset($_GET['code']))
{
    $access_token = $facebook->getAccessTokenFromCode($_GET['code'],REDIRECT_URI);
     $facebook->setAccessToken($access_token);
    $query = mysql_query("SELECT `title` FROM `tentego_img` WHERE `id` = ".intval($_GET['id'])."");
    $r = mysql_fetch_array($query);
    $link = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

    $facebook->api('/me/feed', 'POST',
                                    array(
                                      'link' => $link,
                                      'message' => $r[0]
                                 ));
}else
{
    $login_url = $facebook->getLoginUrl($params =array('redirect_uri'=>REDIRECT_URI,'scope' => PERMISSIONS_REQUIRED));
 echo ("<script> top.location.href='".$login_url."'</script>");
}
于 2013-02-28T20:18:57.727 回答