【问题标题】:FQL - "An access token is required to use this resource."FQL - “使用此资源需要访问令牌。”
【发布时间】:2014-03-02 22:35:51
【问题描述】:

我正在尝试获取我的所有状态更新并将它们显示在我的应用程序中。我将 OAuth 令牌存储在数据库中。

这段代码从数据库中获取access_token,并构造一个url进行查询

include ('fbconfig.php');
include ('inc/facebook.php');

// make new facebook object
$facebook = new Facebook(array(
        'appId' => APP_ID,
        'secret' => APP_SECRET,
        'cookie' => true
));

$username = $_SESSION['username'];

// get the access token from database 
$sql = "SELECT fb_token FROM users";
$query = mysqli_query($db_conx,$sql);
$row = mysqli_fetch_array($query);
$access_token = $row[0];

// fql query to get fb status updates
$fql = "SELECT uid,time,message FROM status WHERE uid = me()";

// construct query url
$fql_query_url = "https://graph.facebook.com"
. "/fql?q=" . urlencode($fql)
. '&' . $access_token;

echo $fql_query_url;

上面的代码运行后,会输出这个url:

https://graph.facebook.com/fql?q=SELECT+uid%2Ctime%2Cmessage+FROM+status+WHERE+uid+%3D+me%28%29&293721510781740|

当我点击链接时会抛出这个错误(即使它说我在 url 中有一个 access_token):

{"error":{"message":"An access token is required to request this resource.","type":"OAuthException","code":104}}

我已经在这几个小时做了不同的变体,我不明白为什么它没有检索我的状态。

【问题讨论】:

    标签: php facebook-graph-api facebook-fql facebook-php-sdk


    【解决方案1】:

    网址不应该包含

    &access_token=

    ?

    尝试替换:

    $fql_query_url = "https://graph.facebook.com"
    . "/fql?q=" . urlencode($fql)
    . '&' . $access_token;
    

    作者:

    $fql_query_url = "https://graph.facebook.com"
    . "/fql?q=" . urlencode($fql)
    . '&access_token=' . $access_token;
    

    【讨论】:

      猜你喜欢
      • 2012-03-12
      • 1970-01-01
      • 2013-05-22
      • 1970-01-01
      • 2011-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多