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