Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

Pinterest.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 3.33 KiB


001  <?php
002  /**
003   * Pinterest service.
004   *
005   * @author  Pedro Amorim <contact@pamorim.fr>
006   * @license http://www.opensource.org/licenses/mit-license.html MIT License
007   *
008   * @see    https://developers.pinterest.com/docs/api/overview/
009   */
010   
011  namespace OAuth\OAuth2\Service;
012   
013  use OAuth\Common\Consumer\CredentialsInterface;
014  use OAuth\Common\Http\Client\ClientInterface;
015  use OAuth\Common\Http\Exception\TokenResponseException;
016  use OAuth\Common\Http\Uri\Uri;
017  use OAuth\Common\Http\Uri\UriInterface;
018  use OAuth\Common\Storage\TokenStorageInterface;
019  use OAuth\OAuth2\Token\StdOAuth2Token;
020   
021  /**
022   * Pinterest service.
023   *
024   * @author  Pedro Amorim <contact@pamorim.fr>
025   * @license http://www.opensource.org/licenses/mit-license.html MIT License
026   *
027   * @see    https://developers.pinterest.com/docs/api/overview/
028   */
029  class Pinterest extends AbstractService
030  {
031      /**
032       * Defined scopes - More scopes are listed here:
033       * https://developers.pinterest.com/docs/api/overview/.
034       */
035      const SCOPE_READ_PUBLIC = 'read_public';            // read a user’s Pins, boards and likes
036      const SCOPE_WRITE_PUBLIC = 'write_public';           // write Pins, boards, likes
037      const SCOPE_READ_RELATIONSHIPS = 'read_relationships';     // read a user’s follows (boards, users, interests)
038      const SCOPE_WRITE_RELATIONSHIPS = 'write_relationships';    // follow boards, users and interests
039   
040      public function __construct(
041          CredentialsInterface $credentials,
042          ClientInterface $httpClient,
043          TokenStorageInterface $storage,
044          $scopes = [],
045          ?UriInterface $baseApiUri = null
046      ) {
047          parent::__construct(
048              $credentials,
049              $httpClient,
050              $storage,
051              $scopes,
052              $baseApiUri,
053              true
054          );
055   
056          if (null === $baseApiUri) {
057              $this->baseApiUri = new Uri('https://api.pinterest.com/');
058          }
059      }
060   
061      /**
062       * {@inheritdoc}
063       */
064      public function getAuthorizationEndpoint()
065      {
066          return new Uri('https://api.pinterest.com/oauth/');
067      }
068   
069      /**
070       * {@inheritdoc}
071       */
072      public function getAccessTokenEndpoint()
073      {
074          return new Uri('https://api.pinterest.com/v1/oauth/token');
075      }
076   
077      /**
078       * {@inheritdoc}
079       */
080      protected function getAuthorizationMethod()
081      {
082          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
083      }
084   
085      /**
086       * {@inheritdoc}
087       */
088      protected function parseAccessTokenResponse($responseBody)
089      {
090          $data = json_decode($responseBody, true);
091   
092          if (null === $data || !is_array($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          }
099   
100          $token = new StdOAuth2Token();
101          $token->setAccessToken($data['access_token']);
102   
103          if (isset($data['expires_in'])) {
104              $token->setLifeTime($data['expires_in']);
105              unset($data['expires_in']);
106          }
107          // I hope one day Pinterest add a refresh token :)
108          if (isset($data['refresh_token'])) {
109              $token->setRefreshToken($data['refresh_token']);
110              unset($data['refresh_token']);
111          }
112   
113          unset($data['access_token']);
114   
115          $token->setExtraParams($data);
116   
117          return $token;
118      }
119  }
120