-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.php
32 lines (24 loc) · 1.02 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
include "config.php";
use Abraham\TwitterOAuth\TwitterOAuth;
/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
/* Get temporary credentials. */
$request_token = $connection->oauth('oauth/request_token', ['oauth_callback' => OAUTH_CALLBACK]);
/* If last connection failed don't display authorization link. */
switch ($connection->getLastHttpCode()) {
case 200:
/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
/* Build authorize URL and redirect user to Twitter. */
$url = $connection->url('oauth/authorize', ['oauth_token' => $request_token['oauth_token']]);
break;
default:
/* Show notification if something went wrong. */
echo 'Could not connect to Twitter. Refresh the page or try again later.';
}
if(isset($url)) {
print "<a href=".$url.">Sign In</a>";
}
?>