簡體   English   中英

在Linux服務器上使用curl為Facebook獲取訪問令牌

[英]Getting the access token for facebook using curl on a linux server

我在嘗試使用cURL從Linux服務器上的Facebook獲取訪問令牌時遇到問題。 在Windows計算機上,當我在XAMPP下運行PHP時,一切正常,但在Linux中則無法正常工作。

我已經在Linux服務器上安裝了cURL,現在正在嘗試使用它,但是它不返回任何信息。

我的代碼如下:

$url = "https://graph.facebook.com/oauth/access_token?client_id=278313225526998&redirect_uri=thejunction.africanbank.net/baobab/baobab.php&client_secret=$app_secret&code=$code";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: graph.facebook.com'));
$access_token = curl_exec($ch);
curl_close($ch); 
echo "access is: ".$access_token;

有人可以讓我知道我在這里做錯了什么嗎? 它給了我錯誤:

An error occured while fetching the URI

我也嘗試使用

  $url = 'http://www.stackoverflow.com'; //curl script to get content of given url $ch = curl_init(); // set the target url curl_setopt($ch, CURLOPT_URL,$url); // request as if Firefox curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); curl_setopt($ch, CURLOPT_NOBODY, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result= curl_exec ($ch); curl_close ($ch); echo "result is".$result; 

這給我一個錯誤

An error occured while fetching the URI. Please retry.

並在我的php.ini文件中啟用了curl功能,請查看圖片 在此處輸入圖片說明

伙計們可能是什么問題? 請幫我。

謝謝唐納德

您的redirect_uri錯誤。 它應該是

  1. 編碼的
  2. 與http(s)

所以改變

$url = "https://graph.facebook.com/oauth/access_token?client_id=278313225526998&redirect_uri=thejunction.africanbank.net/baobab/baobab.php&client_secret=$app_secret&code=$code";

$url = "https://graph.facebook.com/oauth/access_token?client_id=278313225526998&redirect_uri=".urlencode("http://thejunction.africanbank.net/baobab/baobab.php")."&client_secret=$app_secret&code=$code";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM