I've been working on some IG API and when I try to get the IG username I get this error
I just don't see anything wrong with my code did I miss something ??
( ! ) Notice: Undefined index: user in C:\wamp\www\folder\index.php on line 39

<?php 
set_time_limit(0);
ini_set('default_socket_timeout', 300);
session_start();


/*API*/
define("clientID", '#########################');
define("clientSecret", '#########################');
define("redirectURI", 'http://localhost/folder/index.php');


 if(isset($_GET['code'])){



    $code = $_GET['code'];
    $url = "https://api.instagram.com/oauth/access_token";
    $access_token_setting = array
    (
        'client_id'      =>clientID,
        'client_secret'  =>clientSecret,
        'grant_type'     => 'autiruzation_code',
        'redirect_uri'   => redirectURI,
        'code'           => $code,


    );
    $curl=curl_init($url);
    curl_setopt($curl, CURLOPT_POST,true);
    curl_setopt($curl, CURLOPT_POSTFIELDS,$access_token_setting);
        //get as string 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER ,1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER ,false);

     $result = curl_exec($curl);
     curl_close($curl);
     $resutls = json_decode($result,true);
    echo $resutls['user']['username'];



 }else{ ?> <!DOCTYPE html> <html> <body> <a href="https://api.instagram.com/oauth/authorize/?client_id=<?php echo clientID;?>&redirect_uri=<?php echo redirectURI;?>&response_type=code">log in</a> </body> </html> <?php
 }
?> 

var_dump out the contents of $results and see what it contains. It is clear from the error that $results['user'] isn't an existing item. It maybe as simple as the 'user' item being wrapped in an outer element you're not referring to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.