1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Example of retrieving an authentication token of the Etsy service. |
||
5 | * |
||
6 | * PHP version 5.4 |
||
7 | * |
||
8 | * @author Iñaki Abete <[email protected]> |
||
9 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
||
10 | */ |
||
11 | |||
12 | use OAuth\Common\Consumer\Credentials; |
||
13 | use OAuth\Common\Storage\Session; |
||
14 | use OAuth\OAuth1\Service\Etsy; |
||
15 | |||
16 | /** |
||
17 | * Bootstrap the example. |
||
18 | */ |
||
19 | require_once __DIR__ . '/bootstrap.php'; |
||
20 | |||
21 | // Session storage |
||
22 | $storage = new Session(); |
||
23 | |||
24 | // Setup the credentials for the requests |
||
25 | $credentials = new Credentials( |
||
26 | $servicesCredentials['etsy']['key'], |
||
27 | $servicesCredentials['etsy']['secret'], |
||
28 | $currentUri->getAbsoluteUri() |
||
29 | ); |
||
30 | |||
31 | // Instantiate the Etsy service using the credentials, http client and storage mechanism for the token |
||
32 | /** @var Etsy $etsyService */ |
||
33 | $etsyService = $serviceFactory->createService('Etsy', $credentials, $storage); |
||
34 | |||
35 | if (!empty($_GET['oauth_token'])) { |
||
36 | $token = $storage->retrieveAccessToken('Etsy'); |
||
37 | |||
38 | // This was a callback request from Etsy, get the token |
||
39 | $etsyService->requestAccessToken( |
||
40 | $_GET['oauth_token'], |
||
41 | $_GET['oauth_verifier'], |
||
42 | $token->getRequestTokenSecret() |
||
43 | ); |
||
44 | |||
45 | // Send a request now that we have access token |
||
46 | $result = json_decode($etsyService->request('/private/users/__SELF__')); |
||
47 | |||
48 | echo 'result: <pre>' . print_r($result, true) . '</pre>'; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
49 | } elseif (!empty($_GET['go']) && $_GET['go'] === 'go') { |
||
50 | $response = $etsyService->requestRequestToken(); |
||
51 | $extra = $response->getExtraParams(); |
||
52 | $url = $extra['login_url']; |
||
53 | header('Location: ' . $url); |
||
54 | } else { |
||
55 | $url = $currentUri->getRelativeUri() . '?go=go'; |
||
56 | echo "<a href='$url'>Login with Etsy!</a>"; |
||
57 | } |
||
58 |