登录正常。但我无法通过access_token
获取数据。如何获取数据?顺便说一下,我的应用程序处于沙盒模式。它有所作为吗?我使用与应用程序管理员相同的帐户登录。
<?php
set_time_limit(0);
ini_set('default_socket_timeout', 300);
session_start();
// instagram details
define('clientID', MY-ID);
define('clientSecret', MY-SECRET);
define('redirectURI', 'http://localhost/pixela/insta_test.php');
// check login
$link = '<a href="http://api.instagram.com/oauth/authorize/?client_id='.clientID.'&redirect_uri='.redirectURI.'&response_type=code">Login to Instagram</a>';
if (isset($_GET["code"])) {
$code = $_GET["code"];
$url = 'http://api.instagram.com/oauth/access_token';
$access_token_settings = 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_settings);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
$results = json_decode($result, true);
echo 'u-'.$results['user']['username'];
$link = '<a href="">Get photos</a>';
}
?>
<!doctype html>
<html>
<head>
<title>Testing Instagram API</title>
</head>
<body>
<?php echo $link; ?>
</body>
</html>