phptwitteroauth

Show userpic of Twitter account on the page using TwitterOAuth


I use http://github.com/abraham/twitteroauth PHP library for reaching Twitter REST API:

<?php
    session_start(); 
    require("config.php");
    require("twitteroauth/twitteroauth.php");
    if(!empty($_GET['oauth_verifier']) &&
       !empty($_SESSION['oauth_token']) &&
       !empty($_SESSION['oauth_token_secret'])
    )
    {                        
        $twitteroauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);  
        $access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']); 
        $_SESSION['access_token'] = $access_token; 
        $user_info = $twitteroauth->get('account/verify_credentials');
        // ?...
?>

How can I render the Twitter userpic on the HTML page?


Solution

  • [EDIT]

    Just do this:

    echo '<img src="'.$user_info->profile_image_url.'"/>';
    

    The account/verify_credentials call returns all the user variables. So, no need to do another call.

    [Old Answer]

    Use users show method. It returns a field called profile_image_url which you need. It's the URL of the photo of the user.