Cómo Obtener el Token de Acceso a Instagram Usando Php

by Luigi Nori Date: 30-07-2019 php token key instagram api


Cómo obtener el token de acceso a Instagram usando PHP?

Para obtener el token de acceso Instagram, primero debes autenticar tu aplicación y luego obtener el token de acceso.

Sigue los siguientes pasos para obtener el token de acceso:

Paso 1: Crea una aplicación (app) y obten tu client-key y secret-key.

Necesitas crear una aplicación aquí: https://www.instagram.com/developer/

Paso 2: Autentifica tu aplicación y obten accesstoken

authenticate.php

< ? php
$insta_client_id = 'CLIENT_ID';
$insta_client_secret = 'SECRET_CODE';
$insta_redirect_uri = 'https://your-url.com/authenticate.php';
$authentication_url = "https://api.instagram.com/oauth/authorize?client_id=".$insta_client_id."&redirect_uri=".$insta_redirect_uri."&response_type=code";
if(isset($_GET['code'])){
$code = $_GET['code'];
$uri = 'https://api.instagram.com/oauth/access_token'; 
$data = [
'client_id' => $insta_client_id, 
'client_secret' => $insta_client_secret, 
'grant_type' => 'authorization_code', 
'redirect_uri' => $insta_redirect_uri, 
'code' => $code
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri); // uri
curl_setopt($ch, CURLOPT_POST, true); // POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // POST DATA
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN RESULT true
curl_setopt($ch, CURLOPT_HEADER, 0); // RETURN HEADER false
curl_setopt($ch, CURLOPT_NOBODY, 0); // NO RETURN BODY false / we need the body to return
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // VERIFY SSL HOST false
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // VERIFY SSL PEER false
$result = json_decode(curl_exec($ch)); // execute curl
echo '
< pre >'; // preformatted view
//ecit directly the result
//exit(print_r($result)); 
echo $result->access_token;
echo'
< br >';
$user = $result->user;
echo $user->id;
} else {
? >
< a href=" < ? echo $authentication_url; ? > "> Click here to Authenticate < /a >
< ? } ? >


Snippet en GitHub

 
by Luigi Nori Date: 30-07-2019 php token key instagram api visitas : 3460  
 
Luigi Nori

Luigi Nori

He has been working on the Internet since 1994 (practically a mummy), specializing in Web technologies makes his customers happy by juggling large scale and high availability applications, php and js frameworks, web design, data exchange, security, e-commerce, database and server administration, ethical hacking. He happily lives with @salvietta150x40, in his (little) free time he tries to tame a little wild dwarf with a passion for stars.

 
 
 

Artículos relacionados