R
R
redd_i2018-02-09 13:43:36
PHP
redd_i, 2018-02-09 13:43:36

How to make an authorization through instagram?

Hello. I'm trying to login to a website with instagram. I do something like in this article: https://php-academy.kiev.ua/blog/pokorenie-instagr...
And so. i have a button:

<a href="https://api.instagram.com/oauth/authorize?client_id=<?=IDINS?>&redirect_uri=<?=URLINS?>&scope=basic&response_type=code">Instagram</a>

All parameters are passed correctly. Then there is a redirect to the page I need /insta.php with the "code" parameter and the key itself.
insta.php code
<?php


$app->get('/login', function () use ($app, $client) {

    $data = array();

    $login_url = '';

    if($app->request->get('code')){

        $code = $app->request->get('code');

        $response = $client->post('https://api.instagram.com/oauth/access_token', array('body' => array(

            'client_id' => IDINS,

            'client_secret' => SECRETINS,

            'grant_type' => 'authorization_code',

            'redirect_uri' => URLINS,

            'code' => $code

        )));

        $data = $response->json();

    }else{

        $login_url = "https://api.instagram.com/oauth/authorize?client_id=IDINS&redirect_uri=URLINS&scope=basic&response_type=code";

    }

    $app->render('home.php', array('data' => $data, 'login_url' => $login_url));

});

?>

But when redirecting to this page, an error is thrown:
Fatal error: Uncaught Error: Call to a member function get() on null in /home/u93316/insta.php:4 Stack trace: #0 {main} thrown in /home/ u93316/insta.php on line 4 I
also took the code from the article: https://php-academy.kiev.ua/blog/pokorenie-instagr...
Please tell me how to display ID and Username from Instagram on the insta.php page ) I will be very grateful

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg, 2018-02-09
@402d

Did you notice that the example is designed for the Slim framework?
I don’t see in the code
a) composer autoload
b) $app initialization by slim
https://gist.github.com/anonymous/6516521b1fb3b464...
https://core.telegram.org/widgets/login
https://telegram.org /blog/login
from February 6 simplified

P
Puma Thailand, 2018-02-09
@opium

You haven’t created an APP anywhere, let alone defined it, try reading a php book for idiots to get started

R
redd_i, 2018-02-09
@redd_i

Found an option: https://www.youtube.com/watch?v=Hi-wVYiJ5fk&list=P...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question