2016-09-23 67 views
-3

我需要更換與file_get_content捲曲(我已刪除敏感信息):更換捲曲與file_get_content

curl -F 'client_id=aaa' \ 
    -F 'client_secret=bbb' \ 
    -F 'grant_type=authorization_code' \ 
    -F 'redirect_uri=http://testtest.altervista.org/instagram/' \ 
    -F 'code=ccc' \ 
    https://api.instagram.com/oauth/access_token 

我tryed這一點,但好好嘗試一下工作(它返回任何結果):

$url = 'https://api.instagram.com/oauth/access_token?client_id=aaa&client_secret=bbb&grant_type=authorization_code&redirect_uri=http://testtest.altervista.org/instagram/&code=ccc'; 
print json_decode(file_get_contents($url));  

爲什麼?

+0

當您在瀏覽器中運行該URL時,您會得到什麼? – Exception

+1

您正在用php file_get_contents替換'shell'cURL命令......您在這裏的真正目標是什麼? – YvesLeBorg

+0

當你在URL中有一個URL時,內部URL必須是'urlencode()'。如果您什麼都沒有收到,那麼顯示錯誤日誌或至少顯示調用返回的標題和狀態代碼會很有幫助。 – DanFromGermany

回答

3

不知道你爲什麼要把cURL改成file_get_contents,但我至少要確保對你正在嘗試使用的查詢字符串進行編碼。您可以使用http_build_query以獲得正確的結果

$query = array(
    'client_id' => 'aaa', 
    'client_secret' => 'bbb', 
    'grant_type' => 'authorization_code', 
    'redirect_uri' => 'http://testtest.altervista.org/instagram/', 
    'code' => 'ccc 
); 

$domain = 'https://api.instagram.com/oauth/access_token?' 
$url = $domain . http_build_query($data); 
print json_decode(file_get_contents($url));