我想這個URL時出現以下錯誤時(只是將其粘貼在瀏覽器中檢查輸出):OAuthException做一個網站查詢
https://graph.facebook.com/search?q=London&type=event&access_token=ACCESS_TOKEN
{ "error": {
"message": "(#200) Must have a valid access_token to access this endpoint",
"type": "OAuthException",
"code": 200
}
}
我按照this guide得到了ACCESS_TOKEN
。我究竟做錯了什麼?
解
由於Rahil Arora的小費。這裏是我如何打印出我的訪問令牌:
我把這個放在我的私人網站上。將FB應用程序的公共URL設置爲指向該網頁後,我只需單擊「登錄」按鈕即可。然後有一個彈出窗口允許我的應用程序訪問我的個人數據,瞧!它打印出來的訪問令牌;)
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://connect.facebook.net/en_US/all.js"></script>
</head>
<body>
<button id="login">Login to FB</button>
<p>Access token: <span id="token"></span>
<script>
$(function() {
FB.init({
appId : 'APP-ID', // App ID
channelUrl : '', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true
});
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status === 'connected') {
$('#token').html(response.authResponse.accessToken);
}
});
$('#login').click(function(e) {
FB.login();
});
});
</script>
</body>
</html>
奇怪,我認爲公共事件落在了地方的對象之下?關於用戶訪問令牌的文檔如下: '這種訪問令牌在應用程序調用API來代替它們讀取,修改或編寫特定人員的Facebook數據時需要。 ' 但是我只想讀取公開數據 –
不過,您需要訪問令牌,因爲所有Graph API搜索都需要訪問令牌。它在文檔中提到。我使用用戶訪問令牌(在Graph API Explorer上)嘗試了相同的查詢,並且它對我來說非常合適。 –
@ArnabDatta你能解決這個問題嗎? –