[英]What is the proper way to get a 60 day long living access token using Facebook PHP SDK?
[英]PHP + Facebook: how to get access_token + 60 day long access token?
我試圖這樣做:
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
url地址中的所有變量都已正確設置,但是當我將此url放入瀏覽器時,我得到:
{
"error": {
"message": "No user access token specified",
"type": "OAuthException",
"code": 1
}
}
一遍又一遍地。 我究竟做錯了什么?
編輯:
我目前的設置:腳本的地址: www.domain.com/folder/index.php
$my_url = "www.domain.com"
在Facebook: namespace
:my_namespace
應用域名 :domain.com
網站網址 : http://www.domain.com/
: http://www.domain.com/
這是我的設置,但仍然得到相同的錯誤
您是否向他們發送現有的訪問令牌? 您應首先擁有一個access_token,您應該發送回來獲取擴展的到期訪問令牌。
從錯誤中,我可以理解的是,您沒有向他們發送令牌。
這是我在其他一些問題中回答的代碼。它在FB docs中明確給出。這個獲取了短暫的令牌,將其發回以擴展它,並獲得長期存在的access_token。
<?php
//read more : https://developers.facebook.com/docs/howtos/login/server-side-login/
session_start();
$app_id = "xxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxx";
$my_url = "www.stackoverflow.com/"; // redirect url
$code = $_REQUEST["code"];
if(empty($code)) {
// Redirect to Login Dialog
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'] . "&scope=publish_stream,read_friendlists,email";
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_SESSION['state'] && ($_SESSION['state'] === $_REQUEST['state'])) {
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$longtoken=$params['access_token'];
//save it to database
?>
你不能在那里放置App令牌。 它必須是用戶訪問令牌。 請使用現有的用戶訪問令牌。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.