我正在尝试获取所有状态更新并将其显示在我的应用中。我将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|
点击链接时会抛出此错误(即使它表示我在网址中有access_token):
{"error":{"message":"An access token is required to request this resource.","type":"OAuthException","code":104}}
我已经在这里工作了几个小时做了不同的变化,我不明白为什么它没有检索我的状态。
答案 0 :(得分: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;