Instagram-basi c -display-api проблема с получением имени пользователя - access_token и user_id успешно получены - PullRequest
0 голосов
/ 10 апреля 2020

У меня возникли проблемы с получением имени пользователя из базового c API-интерфейса Instagram. Я думаю, что в моей кодировке есть ошибка. Я пытаюсь в течение 3 дней, но не удалось. Проблема в том, что я получаю Instagram access_token и user_id, но потом я не могу получить имя пользователя из этих access_token и user_id. Я написал код для этого, но в результате я получаю пустые результаты. Пожалуйста, посмотрите на мой код, чтобы понять мою проблему:

if(isset($_GET['code'])){
$endpoint = 'https://api.instagram.com

/oauth/access_token';

// params the endpoint requires
$params = array(
    'app_id' => 'my_api_id ', // our instagram app id
    'app_secret' => 'my_app_secret', // our instagram app secret
    'grant_type' => 'authorization_code',
    'redirect_uri' => 'my_redirect_urin', // our redirect uri
    'code' => $_GET['code'] // code instagram sent us in the URL
);          

// open curl call
$ch = curl_init();

// set type to post and pass the fields along 
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params ) );
curl_setopt( $ch, CURLOPT_POST, 1 );

// set curl url
curl_setopt( $ch, CURLOPT_URL, $endpoint );

// set other curl options
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); 
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

// get response, close curl, make php array
$response = curl_exec( $ch );

// close cur
curl_close( $ch );

// make nice php array :D
$responseArray = json_decode( $response, true );

// print out the response array that contains the access token
echo '<pre>';
print_r( $responseArray );


/// working fine till first response and getting acces_token and user_id..............


// after that I am not getting results.................................

if(isset($responseArray)){

$endpoint_url = 'https://graph.instagram.com/'.$responseArray['user_id'].'?fields=id,username&access_token='.$responseArray1['access_token'];



$ch = curl_init();
curl_setopt( $ch, CURLOPT_POST, 1 );

// general curl options
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec( $ch );
curl_close( $ch );
var_dump($response);
$responseArray1 = json_decode( $response, true );
print_r($responseArray1);

}

Я получаю хорошие результаты до первого ответа и получения access_token и user_id, но затем после этого я не получаю username.

Пожалуйста, посмотрите вывод: Только получение access_toke и user_id, а не username. Есть ли какая-либо ошибка в моем запросе curl?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...