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

Pinterest.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.34 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   * @link    https://developers.pinterest.com/docs/api/overview/
 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   * Pinterest service.
 022   *
 023   * @author  Pedro Amorim <contact@pamorim.fr>
 024   * @license http://www.opensource.org/licenses/mit-license.html MIT License
 025   * @link    https://developers.pinterest.com/docs/api/overview/
 026   */
 027  class Pinterest extends AbstractService
 028  {
 029      /**
 030       * Defined scopes - More scopes are listed here:
 031       * https://developers.pinterest.com/docs/api/overview/
 032       */
 033      const SCOPE_READ_PUBLIC         = 'read_public';            // read a user’s Pins, boards and likes
 034      const SCOPE_WRITE_PUBLIC        = 'write_public';           // write Pins, boards, likes
 035      const SCOPE_READ_RELATIONSHIPS  = 'read_relationships';     // read a user’s follows (boards, users, interests)
 036      const SCOPE_WRITE_RELATIONSHIPS = 'write_relationships';    // follow boards, users and interests
 037   
 038      public function __construct(
 039          CredentialsInterface $credentials,
 040          ClientInterface $httpClient,
 041          TokenStorageInterface $storage,
 042          $scopes = array(),
 043          UriInterface $baseApiUri = null
 044      ) {
 045          parent::__construct(
 046              $credentials,
 047              $httpClient,
 048              $storage,
 049              $scopes,
 050              $baseApiUri,
 051              true
 052          );
 053   
 054          if (null === $baseApiUri) {
 055              $this->baseApiUri = new Uri('https://api.pinterest.com/');
 056          }
 057      }
 058   
 059      /**
 060       * {@inheritdoc}
 061       */
 062      public function getAuthorizationEndpoint()
 063      {
 064          return new Uri('https://api.pinterest.com/oauth/');
 065      }
 066   
 067      /**
 068       * {@inheritdoc}
 069       */
 070      public function getAccessTokenEndpoint()
 071      {
 072          return new Uri('https://api.pinterest.com/v1/oauth/token');
 073      }
 074   
 075      /**
 076       * {@inheritdoc}
 077       */
 078      protected function getAuthorizationMethod()
 079      {
 080          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
 081      }
 082   
 083      /**
 084       * {@inheritdoc}
 085       */
 086      protected function parseAccessTokenResponse($responseBody)
 087      {
 088          $data = json_decode($responseBody, true);
 089   
 090          if (null === $data || !is_array($data)) {
 091              throw new TokenResponseException('Unable to parse response.');
 092          } elseif (isset($data['error'])) {
 093              throw new TokenResponseException(
 094                  'Error in retrieving token: "' . $data['error'] . '"'
 095              );
 096          }
 097   
 098          $token = new StdOAuth2Token();
 099          $token->setAccessToken($data['access_token']);
 100   
 101          if (isset($data['expires_in'])) {
 102              $token->setLifeTime($data['expires_in']);
 103              unset($data['expires_in']);
 104          }
 105          // I hope one day Pinterest add a refresh token :)
 106          if (isset($data['refresh_token'])) {
 107              $token->setRefreshToken($data['refresh_token']);
 108              unset($data['refresh_token']);
 109          }
 110   
 111          unset($data['access_token']);
 112   
 113          $token->setExtraParams($data);
 114   
 115          return $token;
 116      }
 117  }
 118