我一直在研究一些IG API,当我尝试获取IG用户名时,我收到了这个错误 我只是没有看到我的代码有什么问题我错过了什么? (!)注意:未定义的索引:用户在C:\ wamp \ www \ IG \ index.php的echo $ res ['user'] ['username'];
编辑: 所以我注意到我的代码中有一些拼写错误,在修复它之后,检查文档我仍然得到了同样的错误我甚至应用了但是它没有修复它
<?php
set_time_limit(0);
ini_set('default_socket_timeout', 300);
session_start();
/*API*/
define("clientID", '#########################');
define("clientSecret", '#########################');
define("redirectURI", 'http://localhost/folder/index.php');
if(isset($_GET['code'])){
//logged in
$code = $_GET['code'];
$url = "https://api.instagram.com/oauth/access_token";
$access_token_setting = array
(
'client_id' =>clientID,
'client_secret' =>clientSecret,
'grant_type' => 'authorization_code ',
'redirect_uri' => redirectURI,
'code' => $code,
);
$curl=curl_init($url);
curl_setopt($curl, CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_POSTFIELDS,$access_token_setting);
//get as string
curl_setopt($curl, CURLOPT_RETURNTRANSFER ,1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER ,false);
$result = curl_exec($curl);
curl_close($curl);
$res = json_decode($result,true);
print_r($res);
echo $res['user']['username'];
}else{
?>
<!DOCTYPE html>
<html>
<body>
<a href="https://api.instagram.com/oauth/authorize/?client_id=<?php echo clientID;?>&redirect_uri=<?php echo redirectURI;?>&response_type=code">log in</a>
</body>
</html>
<?php
}
?>
答案 0 :(得分:0)
检查您的响应数组。这说明响应数组中没有用户索引。而不是echo $ result [&#39; user&#39;]回显整个$ result。然后做调试......