Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Foursquare.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 2.37 KiB


 01  <?php
 02  namespace OAuth\OAuth2\Service;
 03   
 04  use OAuth\OAuth2\Token\StdOAuth2Token;
 05  use OAuth\Common\Http\Exception\TokenResponseException;
 06  use OAuth\Common\Http\Uri\Uri;
 07  use OAuth\Common\Consumer\Credentials;
 08  use OAuth\Common\Http\Client\ClientInterface;
 09  use OAuth\Common\Storage\TokenStorageInterface;
 10  use OAuth\Common\Http\Uri\UriInterface;
 11   
 12  class Foursquare extends AbstractService
 13  {
 14      private $apiVersionDate = '20130829';
 15   
 16      public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
 17      {
 18          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
 19          if( null === $baseApiUri ) {
 20              $this->baseApiUri = new Uri('https://api.foursquare.com/v2/');
 21          }
 22      }
 23   
 24      /**
 25       * @return \OAuth\Common\Http\Uri\UriInterface
 26       */
 27      public function getAuthorizationEndpoint()
 28      {
 29          return new Uri('https://foursquare.com/oauth2/authenticate');
 30      }
 31   
 32      /**
 33       * @return \OAuth\Common\Http\Uri\UriInterface
 34       */
 35      public function getAccessTokenEndpoint()
 36      {
 37          return new Uri('https://foursquare.com/oauth2/access_token');
 38      }
 39   
 40      /**
 41       * @param string $responseBody
 42       * @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth2\Token\StdOAuth2Token
 43       * @throws \OAuth\Common\Http\Exception\TokenResponseException
 44       */
 45      protected function parseAccessTokenResponse($responseBody)
 46      {
 47          $data = json_decode( $responseBody, true );
 48   
 49          if( null === $data || !is_array($data) ) {
 50              throw new TokenResponseException('Unable to parse response.');
 51          } elseif( isset($data['error'] ) ) {
 52              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
 53          }
 54   
 55          $token = new StdOAuth2Token();
 56   
 57   
 58          $token->setAccessToken( $data['access_token'] );
 59          // Foursquare tokens evidently never expire...
 60          $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
 61          unset( $data['access_token'] );
 62          $token->setExtraParams( $data );
 63   
 64          return $token;
 65      }
 66   
 67      public function request($path, $method = 'GET', $body = null, array $extraHeaders = array()){
 68          $uri = new Uri($this->baseApiUri . $path);
 69          $uri->addToQuery('v', $this->apiVersionDate);
 70   
 71          return parent::request($uri, $method = 'GET', $body, $extraHeaders);
 72      }
 73   
 74  }
 75