Stefan
Stefan

Reputation: 155

Use Twitteroauth to acquire twitter user info

I use the following code to set some sessions when an user logs in using his twitter account:

        $twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_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');

As you see, I have all the tokens (token, secret token and access token) stored in a session, so that I can use this later on when an user wants to change his profile picture for example

But when I want to have access again to the user info... I am not able to access it. Again I build the twitteroauth connection, but now using the sessions stored during login:

        $twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    $access_token = $_SESSION['access_token'];
    $user_info = $twitteroauth->get('account/verify_credentials');


    if (isset($user_info->error)) {

        echo "token:", $_SESSION['oauth_token'], "<br>";
        echo "token_secret:", $_SESSION['oauth_token_secret'], "<br>";
        echo "access-token:", $access_token, "<br>";

         echo "error";

    }  else { 

    echo "oke";

    }

I receive the error echo. When I echo my token strings, the all contain data and the access-token contains the value "Array".

Does someone know what I am doing wrong?

Upvotes: 1

Views: 329

Answers (1)

Jeyaganesh
Jeyaganesh

Reputation: 1354

You need to use print_r to print the array values.

Upvotes: 0

Related Questions