-
Notifications
You must be signed in to change notification settings - Fork 25
/
Authorize-oauth1-pecl.php
executable file
·60 lines (52 loc) · 2.59 KB
/
Authorize-oauth1-pecl.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
53
54
55
56
57
58
59
#!/usr/bin/php
<?php
require "consumer_key.php";
require "api_url_base.php";
require "error.php";
$verbose_debug = true;
try {
$oauth_client = new Oauth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth_client->enableDebug();
} catch(OAuthException $E) {
Error("setup exception", $E->getMessage(), null, null, $E->debugInfo);
}
try {
$info = $oauth_client->getRequestToken("$api_url_base/oauth1/request_token/v1", "oob");
# work around our Pecl getRequestToken->array bug https://bugs.php.net/bug.php?id=63572 :
if ( array_key_exists('oauth_token_secret', $info) &&
array_key_exists('authentication_url', $info) &&
! array_key_exists('oauth_token', $info)) {
$urlArray = parse_url($info['authentication_url']);
$info['authentication_url'] = $urlArray['scheme'] .'://'. $urlArray['host'] . $urlArray['path'];
parse_str($urlArray['query']);
$info['oauth_token'] = $oauth_token;
}
if ( array_key_exists('oauth_token', $info) &&
array_key_exists('oauth_token_secret', $info) &&
array_key_exists('authentication_url', $info) ) {
echo "Request token : ".$info['oauth_token']."\n";
echo "Request token secret : ".$info['oauth_token_secret']."\n";
echo "Next please authenticate yourself at ".$info['authentication_url']."?oauth_token=".$info['oauth_token']." and collect the PIN for the next step.\n";
$oauth_client->setToken( $info['oauth_token'] , $info['oauth_token_secret'] );
} else {
Error("getRequestToken", null, $info, $oauth_client->getLastResponseInfo(), null);
}
} catch(OAuthException $E){
Error("getRequestToken", $E->getMessage(), null, $oauth_client->getLastResponseInfo(), $E->debugInfo);
}
$pin = readline("Pin: ");
try {
$info = $oauth_client->getAccessToken("$api_url_base/oauth1/access_token/v1", null, $pin);
if ( array_key_exists('oauth_token', $info) &&
array_key_exists('oauth_token_secret', $info) ) {
echo "Access token : ".$info['oauth_token']."\n";
echo "Access token secret : ".$info['oauth_token_secret']."\n";
echo "\nYou can store these access token values in access_token.php for the other scripts to use.\n";
$oauth_client->setToken( $info['oauth_token'] , $info['oauth_token_secret'] );
} else {
Error("getAccessToken", null, $info, $oauth_client->getLastResponseInfo(), null);
}
} catch(OAuthException $E){
Error("getAccessToken exception", $E->getMessage(), null, $oauth_client->getLastResponseInfo(), $E->debugInfo);
}
?>