[ Index ]

PHP Cross Reference of phpBB-3.3.9-deutsch

title

Body

[close]

/vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/ -> Instagram.php (source)

   1  <?php
   2  
   3  namespace OAuth\OAuth2\Service;
   4  
   5  use OAuth\OAuth2\Token\StdOAuth2Token;
   6  use OAuth\Common\Http\Exception\TokenResponseException;
   7  use OAuth\Common\Http\Uri\Uri;
   8  use OAuth\Common\Consumer\CredentialsInterface;
   9  use OAuth\Common\Http\Client\ClientInterface;
  10  use OAuth\Common\Storage\TokenStorageInterface;
  11  use OAuth\Common\Http\Uri\UriInterface;
  12  
  13  class Instagram extends AbstractService
  14  {
  15      /**
  16       * Defined scopes
  17       * @link http://instagram.com/developer/authentication/#scope
  18       */
  19      const SCOPE_BASIC         = 'basic';
  20      const SCOPE_PUBLIC_CONTENT = 'public_content';
  21      const SCOPE_COMMENTS      = 'comments';
  22      const SCOPE_RELATIONSHIPS = 'relationships';
  23      const SCOPE_LIKES         = 'likes';
  24      const SCOPE_FOLLOWER_LIST = 'follower_list';
  25  
  26      public function __construct(
  27          CredentialsInterface $credentials,
  28          ClientInterface $httpClient,
  29          TokenStorageInterface $storage,
  30          $scopes = array(),
  31          UriInterface $baseApiUri = null
  32      ) {
  33          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true);
  34  
  35          if (null === $baseApiUri) {
  36              $this->baseApiUri = new Uri('https://api.instagram.com/v1/');
  37          }
  38      }
  39  
  40      /**
  41       * {@inheritdoc}
  42       */
  43      public function getAuthorizationEndpoint()
  44      {
  45          return new Uri('https://api.instagram.com/oauth/authorize/');
  46      }
  47  
  48      /**
  49       * {@inheritdoc}
  50       */
  51      public function getAccessTokenEndpoint()
  52      {
  53          return new Uri('https://api.instagram.com/oauth/access_token');
  54      }
  55  
  56      /**
  57       * {@inheritdoc}
  58       */
  59      protected function getAuthorizationMethod()
  60      {
  61          return static::AUTHORIZATION_METHOD_QUERY_STRING;
  62      }
  63  
  64      /**
  65       * {@inheritdoc}
  66       */
  67      protected function parseAccessTokenResponse($responseBody)
  68      {
  69          $data = json_decode($responseBody, true);
  70  
  71          if (null === $data || !is_array($data)) {
  72              throw new TokenResponseException('Unable to parse response.');
  73          } elseif (isset($data['error'])) {
  74              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
  75          }
  76  
  77          $token = new StdOAuth2Token();
  78          $token->setAccessToken($data['access_token']);
  79          // Instagram tokens evidently never expire...
  80          $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
  81          unset($data['access_token']);
  82  
  83          $token->setExtraParams($data);
  84  
  85          return $token;
  86      }
  87  }


Generated: Wed Dec 7 15:09:22 2022 Cross-referenced by PHPXref 0.7.1