2012-03-31 62 views
2

如何使用curl和變量存儲來獲得長壽命的access_token?如何使用curl獲得長壽命access_token?

我的虛擬主機無法使用file_get_contents()由於某些原因,爲什麼我無法使用這個,所以下一個選項可用於我是使用CUrl我知道這一點,學習,但我不明白。

下面

是我們用它來獲得長壽命的access_token注意到我已經存儲了ACCESS_TOKEN在$ atoken

https://graph.facebook.com/oauth/access_token?client_id="id"&client_secret="its seceret ;)"&grant_type=fb_exchange_token&fb_exchange_token=$atoken 

感謝

+0

「如何使用捲曲和變量存儲來獲得長壽命access_token「---任何**真正的原因**爲此?它可以做任何你想要的臨時令牌 – zerkms 2012-03-31 12:13:32

+0

實際上,我希望我的牆更新自動使用我的FB應用程序,並在50天后我的電腦自動打開update.php文件,以便它自動更新長期訪問令牌2,以便我應用程序自動更新我的牆,劑量需要任何用戶交互 – 2012-03-31 12:18:05

+0

張貼到牆上並不需要任何用戶交互和永久令牌。您可以使用常規(臨時)令牌 – zerkms 2012-03-31 12:19:50

回答

1

讓網址簡單的捲曲請求,這樣

$url = 'https://graph.facebook.com/oauth/access_token?client_id="id"&client_secret="its seceret ;)"&grant_type=fb_exchange_token&fb_exchange_token=$atoken'; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_USERAGENT, "I-am-browser"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
$response = curl_exec($ch); 
curl_close($ch); 


var_dump(json_decode($response, true)); 
+0

OK讓我清潔香港謝謝:) – 2012-03-31 12:20:06

+0

我得到了以下錯誤 調用未定義功能url_close() – 2012-03-31 12:25:53

+0

SR男人不好,錯字,現在嘗試 – 2012-03-31 12:27:38