Enter your keyword

Blog

Instagram API how to get user ID?

function getInstaID($username)
{
    $username = strtolower($username); // sanitization
    $token = "InsertThatHere";
    $url = "https://api.instagram.com/v1/users/search?q=".$username."&access_token=".$token;
    $get = file_get_contents($url);
    $json = json_decode($get);
    $output = '';
    foreach($json->data as $user)
    {
    if($user->username == $username)
     {
     // $output .= $user->id 
       $output .= '<div class="result"> ';
       $output .= '<div class="id"><h4>User ID: '.$user->id.'<br></h4></div> ';
       $output .= '<div class="restults">';
       $output .= '<div class="avatar"> <img alt="" src="'.$user->profile_picture.'"></a></div>';
       $output .=	'<div class="text">Username: '.$user->username.'<br>Name: '.$user->full_name.'<br></div>';
       $output .=    '</div>';
       $output .= '</div>';
       //return $user->id;
        }
    }
    return $output; // return this if nothing is found
}

echo getInstaID('aliciakeys'); // this should print 20979117

 

No Comments

Add your review

Your email address will not be published.

* Feilds are Required.