-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
111 lines (85 loc) · 2.75 KB
/
bootstrap.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace PHPoAuthImpl;
/**
* Bootstrap the lib
*/
require_once __DIR__ . '/src/PHPoAuthImpl/bootstrap.php';
exit;
/**
* Create a new instance of the URI class with the current URI, stripping the query string
*/
$uriFactory = new UriFactory();
$currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
$currentUri->setQuery('');
/**
* Load the credentials
*/
require_once __DIR__ . '/credentials.php';
/**
* Setup the token storage
*/
$storage = new Session();
/**
* Setup the service factory
*/
$serviceFactory = new ServiceFactory();
/**
* Setup the credentials for the requests
*/
$credentials = new Credentials(
$credentials['twitter']['key'],
$credentials['twitter']['secret'],
$currentUri->getAbsoluteUri()
);
// Instantiate the twitter service using the credentials, http client and storage mechanism for the token
/** @var $twitterService Twitter */
$twitterService = $serviceFactory->createService('twitter', $credentials, $storage);
if ($storage->hasAccessToken('Twitter')) {
$twitter = new \PHPoAuthImpl\Service\Twitter\Help($twitterService);
echo '<h1>help/tos</h1>';
echo '<pre>';
var_dump($twitter->getTos());
echo '</pre>';
} elseif (!empty($_GET['oauth_token'])) {
$token = $storage->retrieveAccessToken('Twitter');
// This was a callback request from twitter, get the token
$twitterService->requestAccessToken(
$_GET['oauth_token'],
$_GET['oauth_verifier'],
$token->getRequestTokenSecret()
);
$twitter = new \PHPoAuthImpl\Service\Twitter\Help($twitterService);
echo '<h1>help/configuration</h1>';
echo '<pre>';
var_dump($twitter->getConfiguration());
echo '</pre>';
/*
echo '<h1>help/languages</h1>';
echo '<pre>';
var_dump($twitter->getLanguages());
echo '</pre>';
echo '<h1>help/privacy</h1>';
echo '<pre>';
var_dump($twitter->getPrivacy());
echo '</pre>';
echo '<h1>help/tos</h1>';
echo '<pre>';
var_dump($twitter->getTos());
echo '</pre>';
echo '<h1>help/rate-limit-status</h1>';
echo '<pre>';
var_dump($twitter->getRateLimitStatus());
echo '</pre>';
*/
// Send a request now that we have access token
//$result = json_decode($twitterService->request('account/verify_credentials.json'));
//echo 'result: <pre>' . print_r($result, true) . '</pre>';
} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') {
// extra request needed for oauth1 to request a request token :-)
$token = $twitterService->requestRequestToken();
$url = $twitterService->getAuthorizationUri(array('oauth_token' => $token->getRequestToken()));
header('Location: ' . $url);
} else {
$url = $currentUri->getRelativeUri() . '?go=go';
echo "<a href='$url'>Login with Twitter!</a>";
}