Twitter access token generation in php

<code>

if (!isset($_GET[\”oauth_token\”])) {

// set these values in a config file somewhere.

$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);

// append a ?. This is your callback URL if you specify something.

$credentials = $twitter->getRequestToken(\”http://example.com/test.php?\”);

// try and be a bit more elegant with the URL… This is a minimal example

$url = $twitter->getAuthorizeUrl($credentials);

echo $url;

// these are temporary tokens that must be used to fetch the new,

// permanent access tokens. store these in some way,

// session is a decent choice.

$_SESSION[\”token\”] = $credentials[\”oauth_token\”];

$_SESSION[\”secret\”] = $credentials[\”oauth_token_secret\”];

} else {

// use the user\’s previously stored temporary credentials here

$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,

$_SESSION[\”token\”], $_SESSION[\”secret\”]);

// uses the oauth_token (from the request) already.

// you store these credentials in your database (see below).

$credentials = $twitter->getAccessToken($_GET[\”oauth_verifier\”]);

// just a printout of credentials. store these, don\’t display them.

echo \”

\";

var_dump($credentials);

// valid credentials, provided you give the app access to them.

echo \”

\”;

}

</code>

via php – Why is my twitter oauth access token invalid / expired – Stack Overflow.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.