cURL无法解析地址Instagram API


cURL cannot resolve address Instagram API

EDIT:原来这都是因为代理服务器。我通过代理服务器使用互联网,curl没有设置为使用代理服务器我不得不将这些行添加到我的php代码中

 $proxy = '192.168.100.13:8080';
 curl_setopt($ch, CURLOPT_PROXY, $proxy);

如果你想在使用curl和终端时使用代理,请使用

curl --proxy 192.168.100.13:8080 google.com

嘿,伙计们,这是我第一次使用api,我试图从instagramapi中获取信息,但被卡住了。我正在尝试连接instagramapi以获取用户信息CURL给我无法解决的错误。如果我在浏览器中运行该链接,它会显示json。我也用其他网址尝试过这个代码,但结果是一样的。我想从url中提取JSON。

我的php代码是:

<?php 
error_reporting(E_ALL);
$_h = curl_init(); 
curl_setopt($_h, CURLOPT_HEADER, 1); 
curl_setopt($_h, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($_h, CURLOPT_HTTPGET, 1); 
curl_setopt($_h, CURLOPT_URL, 'https://api.instagram.com/v1/users/self/?access_token=ACCESS_TOKEN' ); 
curl_setopt($_h, CURLOPT_DNS_USE_GLOBAL_CACHE, false ); 
curl_setopt($_h, CURLOPT_DNS_CACHE_TIMEOUT, 2 ); 
echo '<br>';echo '<br>';
var_dump(curl_exec($_h)); echo '<br>';echo '<br>';
var_dump(curl_getinfo($_h)); echo '<br>';echo '<br>';
var_dump(curl_error($_h)); 

?>

运行时,我得到

bool(false) 
array(26) 
{ 
["url"]=> string(102) "https://api.instagram.com/v1/users/self/?access_token=ACCESS_TOKEN" 
["content_type"]=> NULL 
["http_code"]=> int(0) 
["header_size"]=> int(0) 
["request_size"]=> int(0) 
["filetime"]=> int(-1) 
["ssl_verify_result"]=> int(0) 
["redirect_count"]=> int(0) 
["total_time"]=> float(0) 
["namelookup_time"]=> float(0) 
["connect_time"]=> float(0) 
["pretransfer_time"]=> float(0) 
["size_upload"]=> float(0) 
["size_download"]=> float(0) 
["speed_download"]=> float(0) 
["speed_upload"]=> float(0) 
["download_content_length"]=> float(-1) 
["upload_content_length"]=> float(-1) 
["starttransfer_time"]=> float(0) 
["redirect_time"]=> float(0) 
["redirect_url"]=> string(0) 
"" ["primary_ip"]=> string(0) "" 
   ["certinfo"]=> array(0) { } 
   ["primary_port"]=> int(0) 
   ["local_ip"]=> string(0) "" 
   ["local_port"]=> int(0) } 
string(41) "Couldn't resolve host 'api.instagram.com'"

我也尝试过使用get_file_contents();

我使用的代码是

$result = file_get_contents('https://api.instagram.com/v1/users/self/?access_token=ACCESS_TOKEN')
var_dump(json_decode($result, true));

这会产生错误

PHP Warning:  file_get_contents(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Applications/MAMP/htdocs

我在php.ini文件中设置了allow_url_fopen=1

我在这里做错了什么,有什么帮助吗?

也许你可以在composer instagram api的帮助下尝试一下:https://github.com/cosenary/Instagram-PHP-API

也许你会从中受益: