forked from abraham/twitteroauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoob2.php
52 lines (38 loc) · 1.33 KB
/
oob2.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Use this after running oob1.php, after you have the PIN code
*
* This is based on callback.php
*
* It takes the PIN code as first parameter.
*/
/* Load lib */
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
if(!file_exists("oauth_token.dat")){
fwrite(STDERR,"Please run oob1.php first. It will create \"oauth_token.dat\"\n");
exit;
}
if($argc!=2){
fwrite(STDERR,"Must give exactly one param: the PIN code\n");
exit;
}
$pin=$argv[1];
$request_token=unserialize(file_get_contents("oauth_token.dat"));
/* Create TwitterOAuth object with app key/secret and token key/secret from default phase */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
$request_token['oauth_token'],$request_token['oauth_token_secret']);
/* Request access tokens from twitter */
$access_token = $connection->getAccessToken($pin);
if($connection->http_code!=200){
fwrite(STDERR,"Failed to getAccessToken; http error:{$connection->http_code}\n");print_r($access_token);
exit;
}
if(!array_key_exists('oauth_token',$access_token)){
fwrite(STDERR,"Failed to getAccessToken:\n");print_r($access_token);
exit;
}
file_put_contents("oauth_success.dat",serialize($access_token));
unlink("oauth_token.dat"); //Not needed any more
print_r($access_token); //Just for debug
?>