Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

Deezer.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.58 KiB


001  <?php
002  /**
003   * Deezer service.
004   *
005   * @author  Pedro Amorim <contact@pamorim.fr>
006   * @license http://www.opensource.org/licenses/mit-license.html MIT License
007   * @link    http://developers.deezer.com/api/
008   */
009   
010  namespace OAuth\OAuth2\Service;
011   
012  use OAuth\OAuth2\Token\StdOAuth2Token;
013  use OAuth\Common\Http\Exception\TokenResponseException;
014  use OAuth\Common\Http\Uri\Uri;
015  use OAuth\Common\Consumer\CredentialsInterface;
016  use OAuth\Common\Http\Client\ClientInterface;
017  use OAuth\Common\Storage\TokenStorageInterface;
018  use OAuth\Common\Http\Uri\UriInterface;
019   
020  /**
021   * Deezer service.
022   *
023   * @author  Pedro Amorim <contact@pamorim.fr>
024   * @license http://www.opensource.org/licenses/mit-license.html MIT License
025   * @link    http://developers.deezer.com/api/
026   */
027  class Deezer extends AbstractService
028  {
029      /**
030       * Defined scopes
031       * http://developers.deezer.com/api/permissions
032       */
033      const SCOPE_BASIC_ACCESS      = 'basic_access';       // Access users basic information
034      const SCOPE_EMAIL             = 'email';              // Get the user's email
035      const SCOPE_OFFLINE_ACCESS    = 'offline_access';     // Access user data any time
036      const SCOPE_MANAGE_LIBRARY    = 'manage_library';     // Manage users' library
037      const SCOPE_MANAGE_COMMUNITY  = 'manage_community';   // Manage users' friends
038      const SCOPE_DELETE_LIBRARY    = 'delete_library';     // Delete library items
039      const SCOPE_LISTENING_HISTORY = 'listening_history';  // Access the user's listening history
040   
041      public function __construct(
042          CredentialsInterface $credentials,
043          ClientInterface $httpClient,
044          TokenStorageInterface $storage,
045          $scopes = array(),
046          UriInterface $baseApiUri = null
047      ) {
048          parent::__construct(
049              $credentials,
050              $httpClient,
051              $storage,
052              $scopes,
053              $baseApiUri,
054              true
055          );
056   
057          if (null === $baseApiUri) {
058              $this->baseApiUri = new Uri('https://api.deezer.com/');
059          }
060      }
061   
062      /**
063       * {@inheritdoc}
064       */
065      public function getAuthorizationEndpoint()
066      {
067          return new Uri('https://connect.deezer.com/oauth/auth.php');
068      }
069   
070      /**
071       * {@inheritdoc}
072       */
073      public function getAccessTokenEndpoint()
074      {
075          return new Uri('https://connect.deezer.com/oauth/access_token.php');
076      }
077   
078      /**
079       * {@inheritdoc}
080       */
081      protected function getAuthorizationMethod()
082      {
083          return static::AUTHORIZATION_METHOD_QUERY_STRING;
084      }
085   
086      /**
087       * {@inheritdoc}
088       */
089      protected function parseAccessTokenResponse($responseBody)
090      {
091          parse_str($responseBody, $data);
092          if (null === $data || !is_array($data) || empty($data)) {
093              throw new TokenResponseException('Unable to parse response.');
094          } elseif (isset($data['error'])) {
095              throw new TokenResponseException(
096                  'Error in retrieving token: "' . $data['error'] . '"'
097              );
098          } elseif (isset($data['error_reason'])) {
099              throw new TokenResponseException(
100                  'Error in retrieving token: "' . $data['error_reason'] . '"'
101              );
102          }
103   
104          $token = new StdOAuth2Token();
105          $token->setAccessToken($data['access_token']);
106          $token->setLifeTime($data['expires']);
107   
108          // I hope one day Deezer add a refresh token :)
109          if (isset($data['refresh_token'])) {
110              $token->setRefreshToken($data['refresh_token']);
111              unset($data['refresh_token']);
112          }
113   
114          unset($data['access_token']);
115          unset($data['expires']);
116   
117          $token->setExtraParams($data);
118   
119          return $token;
120      }
121  }
122