array( 'method' => 'POST' , 'content' => http_build_query( array( 'client_id' => $client_id , 'client_secret' => $client_secret , 'grant_type' => 'authorization_code' , 'redirect_uri' => $redirect_uri , 'code' => $_GET['code'] , ) ) , ) , ) ; // CURLã使ã£ã¦ãªã¯ã¨ã¹ã $curl = curl_init() ; // ãªãã·ã§ã³ã®ã»ãã curl_setopt( $curl , CURLOPT_URL , 'https://api.instagram.com/oauth/access_token' ) ; curl_setopt( $curl , CURLOPT_HEADER, 1 ) ; curl_setopt( $curl , CURLOPT_CUSTOMREQUEST , $context['http']['method'] ) ; // ã¡ã½ãã curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER , false ) ; // 証ææ¸ã®æ¤è¨¼ãè¡ããªã curl_setopt( $curl , CURLOPT_RETURNTRANSFER , true ) ; // curl_execã®çµæãæååã§è¿ã curl_setopt( $curl , CURLOPT_POSTFIELDS , $context['http']['content'] ) ; // ãªã¯ã¨ã¹ããã㣠curl_setopt( $curl , CURLOPT_TIMEOUT , 5 ) ; // ã¿ã¤ã ã¢ã¦ãã®ç§æ° // å®è¡ $res1 = curl_exec( $curl ) ; $res2 = curl_getinfo( $curl ) ; // çµäº curl_close( $curl ) ; // åå¾ãããã¼ã¿ $json = substr( $res1, $res2['header_size'] ) ; // åå¾ãããã¼ã¿(JSONãªã©) $header = substr( $res1, 0, $res2['header_size'] ) ; // ã¬ã¹ãã³ã¹ãããã¼ (æ¤è¨¼ã«å©ç¨ãããå ´åã«ã©ãã) // åå¾ããJSONããªãã¸ã§ã¯ãã«å¤æ $obj = json_decode( $json ) ; // ã¨ã©ã¼å¤å® if( !$obj || !isset($obj->user->id) || !isset($obj->user->username) || !isset($obj->user->profile_picture) || !isset($obj->access_token) ) { $error = 'ãã¼ã¿ãä¸æãåå¾ã§ãã¾ããã§ããâ¦ã' ; } else { // åãã¼ã¿ãæ´ç $user_id = $obj->user->id ; // ã¦ã¼ã¶ã¼ID $user_name = $obj->user->username ; // ã¦ã¼ã¶ã¼ãã¼ã $user_picture = $obj->user->profile_picture ; // ã¦ã¼ã¶ã¼ã¢ã¤ã³ã³ $access_token = $obj->access_token ; // ã¢ã¯ã»ã¹ãã¼ã¯ã³ // ã»ãã·ã§ã³çµäº $_SESSION = array() ; session_destroy() ; // åºåãã $html .= '
ä¸è¨ã®ãã¼ã¿ãåå¾ã§ãã¾ããã
' ; $html .= '' . $error . 'ããä¸åº¦ãèªè¨¼ãããã«ã¯ããã¡ããã¯ãªãã¯ãã¦ä¸ããã
' ; } ?>