carlos-mg89 /
PHPoAuthLib
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * 500px service. |
||
| 5 | * |
||
| 6 | * Example of retrieving an authentication token of the fiveHundredPx service |
||
| 7 | * |
||
| 8 | * @author Pedro Ammorim <[email protected]> |
||
| 9 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
||
| 10 | * |
||
| 11 | * @see https://developers.500px.com/ |
||
| 12 | */ |
||
| 13 | |||
| 14 | use OAuth\Common\Consumer\Credentials; |
||
| 15 | use OAuth\Common\Storage\Session; |
||
| 16 | use OAuth\OAuth1\Service\fiveHundredPx; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Bootstrap the example. |
||
| 20 | */ |
||
| 21 | require_once __DIR__ . '/bootstrap.php'; |
||
| 22 | |||
| 23 | // Session storage |
||
| 24 | $storage = new Session(); |
||
| 25 | |||
| 26 | // Setup the credentials for the requests |
||
| 27 | $credentials = new Credentials( |
||
| 28 | $servicesCredentials['fivehundredpx']['key'], |
||
| 29 | $servicesCredentials['fivehundredpx']['secret'], |
||
| 30 | $currentUri->getAbsoluteUri() |
||
| 31 | ); |
||
| 32 | |||
| 33 | // Instantiate the fiveHundredPx service using the credentials, http client and storage mechanism for the token |
||
| 34 | /** @var fiveHundredPx $fivehundredpxService */ |
||
| 35 | $fivehundredpxService = $serviceFactory->createService('FiveHundredPx', $credentials, $storage); |
||
| 36 | |||
| 37 | if (!empty($_GET['oauth_token'])) { |
||
| 38 | $token = $storage->retrieveAccessToken('FiveHundredPx'); |
||
| 39 | |||
| 40 | // This was a callback request from fivehundredpx, get the token |
||
| 41 | $fivehundredpxService->requestAccessToken( |
||
| 42 | $_GET['oauth_token'], |
||
| 43 | $_GET['oauth_verifier'], |
||
| 44 | $token->getRequestTokenSecret() |
||
| 45 | ); |
||
| 46 | // Send a request now that we have access token |
||
| 47 | $result = json_decode($fivehundredpxService->request('https://api.500px.com/v1/users'), true); |
||
| 48 | |||
| 49 | echo '<img src="' . $result['user']['avatars']['default']['http'] . '"><br><b>' . $result['user']['username'] . '</b><hr>'; |
||
| 50 | echo 'result: <pre>' . print_r($result, true) . '</pre>'; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 51 | } elseif (!empty($_GET['go']) && $_GET['go'] === 'go') { |
||
| 52 | // extra request needed for oauth1 to request a request token :-) |
||
| 53 | $token = $fivehundredpxService->requestRequestToken(); |
||
| 54 | |||
| 55 | $url = $fivehundredpxService->getAuthorizationUri(['oauth_token' => $token->getRequestToken()]); |
||
| 56 | header('Location: ' . $url); |
||
| 57 | } else { |
||
| 58 | $url = $currentUri->getRelativeUri() . '?go=go'; |
||
| 59 | echo "<a href='$url'>Login with fiveHundredPx!</a>"; |
||
| 60 | } |
||
| 61 |