当我来到服务器他的数据时,如何使用php连接到instagram api来验证用户?提前致谢
答案 0 :(得分:4)
首先,您需要注册您的应用: http://instagram.com/developer/clients/manage/
接下来在php处理程序中:
$url = "https://api.instagram.com/oauth/access_token";
$access_token_parameters = array(
'client_id' => '%client_id%',
'client_secret' => '%client_secret%',
'grant_type' => 'authorization_code',
'redirect_uri' => 'http://domain.com/index.php',
'code' => $code
);
$curl = curl_init($url); // we init curl by passing the url
curl_setopt($curl,CURLOPT_POST,true); // to send a POST request
curl_setopt($curl,CURLOPT_POSTFIELDS,$access_token_parameters); // indicate the data to send
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // to stop cURL from verifying the peer's certificate.
$result = curl_exec($curl); // to perform the curl session
curl_close($curl); // to close the curl session
$user_data = json_decode($result,true);