Domanda

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?

È stato utile?

Soluzione

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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top