2016-09-23 33 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));