1
votes

So, i'm using twitter OAuth API and trying to display tweets from my home timeline and it succeed

But, every time i want to access tweets from my home timeline, i need to authorize my application, if i just reload the page where i put the tweets, then the tweet will be empty

I wan't it like dabr, so user login using twitter, and whatever the user does, user doesn't need to authorize the app again

Any solution?

1
You should just save the OAuth instance into $_SESSION. - mpyw
By the way, I produce my very useful library, UltimateOAuth. If you can read Japanese a little, feel free to take a look at GitHub. github.com/Certainist/UltimateOAuth You can also make OAuth authorization as if using xAuth one. I named this para-xAuth Authorization. - mpyw
@CertaiN: what do you mean by OAuth instance (sorry, i'm new to twitter OAuth API), also i don't know japanese language - gamehelp16
What library are you using? twitteroauth.php? - mpyw
yeah, Abaraham's twitter oauth library - gamehelp16

1 Answers

1
votes

Probably you will be helped by setting a TwitterOAuth instance itself into the session.

<?php

// Make sure to load library before starting session
require_once('twitteroauth.php');

session_start();

if (isset(
    $_SESSION['oauth_token'],
    $_SESSION['oauth_token_secret'],
    $_GET['oauth_verifier']
)) {

    // TwitterOAuth instance, with two new parameters we got in twitter_login.php  
    $twitteroauth = new TwitterOAuth('CONSUMER_KEY', 'CONSUMER_SECRET', $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

    // Let's request the access token  
    $twitteroauth->getAccessToken($_GET['oauth_verifier']);

    // Save TwitterOAuth instance in a session var
    $_SESSION['twitteroauth'] = $twitteroauth;

    // Reset parameters
    unset($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

} elseif (isset($_SESSION['twitteroauth'])) {

    $twitteroauth = $_SESSION['twitteroauth'];

} else {

    die('Error');

}


// You can request here using $twitteroauth.