Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 41 lines (33 sloc) 1.503 kB
83e3670 @abraham version 0.2.0-beta. includes support for oauth 1.0a and fixes several…
abraham authored
1 <?php
2 /**
3 * @file
4 * Take the user when they return from Twitter. Get access tokens.
5 * Verify credentials and redirect to based on response from Twitter.
6 */
7
8 /* Start session and load lib */
9 session_start();
10 require_once('twitteroauth/twitteroauth.php');
11 require_once('config.php');
12
13 /* If the oauth_token is old redirect to the connect page. */
14 if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
15 $_SESSION['oauth_status'] = 'oldtoken';
16 header('Location: ./clearsessions.php');
17 }
18
19 /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
20 $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
21
22 /* Request access tokens from twitter */
23 $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
24
25 /* Save the access tokens. Normally these would be saved in a database for future use. */
26 $_SESSION['access_token'] = $access_token;
27
28 /* Remove no longer needed request tokens */
29 unset($_SESSION['oauth_token']);
30 unset($_SESSION['oauth_token_secret']);
31
32 /* If HTTP response is 200 continue otherwise send to connect page to retry */
33 if (200 == $connection->http_code) {
34 /* The user has been verified and the access tokens can be saved for future use */
35 $_SESSION['status'] = 'verified';
36 header('Location: ./index.php');
37 } else {
38 /* Save HTTP status for error dialog on connnect page.*/
39 header('Location: ./clearsessions.php');
40 }
Something went wrong with that request. Please try again.