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

Twitter.php

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


001  <?php
002   
003  namespace OAuth\OAuth1\Service;
004   
005  use OAuth\OAuth1\Signature\SignatureInterface;
006  use OAuth\OAuth1\Token\StdOAuth1Token;
007  use OAuth\Common\Http\Exception\TokenResponseException;
008  use OAuth\Common\Http\Uri\Uri;
009  use OAuth\Common\Consumer\CredentialsInterface;
010  use OAuth\Common\Http\Uri\UriInterface;
011  use OAuth\Common\Storage\TokenStorageInterface;
012  use OAuth\Common\Http\Client\ClientInterface;
013  use OAuth\Common\Exception\Exception;
014   
015  class Twitter extends AbstractService
016  {
017      const ENDPOINT_AUTHENTICATE = "https://api.twitter.com/oauth/authenticate";
018      const ENDPOINT_AUTHORIZE    = "https://api.twitter.com/oauth/authorize";
019   
020      protected $authorizationEndpoint   = self::ENDPOINT_AUTHENTICATE;
021   
022      public function __construct(
023          CredentialsInterface $credentials,
024          ClientInterface $httpClient,
025          TokenStorageInterface $storage,
026          SignatureInterface $signature,
027          UriInterface $baseApiUri = null
028      ) {
029          parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
030   
031          if (null === $baseApiUri) {
032              $this->baseApiUri = new Uri('https://api.twitter.com/1.1/');
033          }
034      }
035   
036      /**
037       * {@inheritdoc}
038       */
039      public function getRequestTokenEndpoint()
040      {
041          return new Uri('https://api.twitter.com/oauth/request_token');
042      }
043   
044      /**
045       * {@inheritdoc}
046       */
047      public function getAuthorizationEndpoint()
048      {
049          if ($this->authorizationEndpoint != self::ENDPOINT_AUTHENTICATE
050          && $this->authorizationEndpoint != self::ENDPOINT_AUTHORIZE) {
051              $this->authorizationEndpoint = self::ENDPOINT_AUTHENTICATE;
052          }
053          return new Uri($this->authorizationEndpoint);
054      }
055   
056      /**
057       * @param string $authorizationEndpoint
058       *
059       * @throws Exception
060       */
061      public function setAuthorizationEndpoint($endpoint)
062      {
063          if ($endpoint != self::ENDPOINT_AUTHENTICATE && $endpoint != self::ENDPOINT_AUTHORIZE) {
064              throw new Exception(
065                  sprintf("'%s' is not a correct Twitter authorization endpoint.", $endpoint)
066              );
067          }
068          $this->authorizationEndpoint = $endpoint;
069      }
070   
071      /**
072       * {@inheritdoc}
073       */
074      public function getAccessTokenEndpoint()
075      {
076          return new Uri('https://api.twitter.com/oauth/access_token');
077      }
078   
079      /**
080       * {@inheritdoc}
081       */
082      protected function parseRequestTokenResponse($responseBody)
083      {
084          parse_str($responseBody, $data);
085   
086          if (null === $data || !is_array($data)) {
087              throw new TokenResponseException('Unable to parse response.');
088          } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
089              throw new TokenResponseException('Error in retrieving token.');
090          }
091   
092          return $this->parseAccessTokenResponse($responseBody);
093      }
094   
095      /**
096       * {@inheritdoc}
097       */
098      protected function parseAccessTokenResponse($responseBody)
099      {
100          parse_str($responseBody, $data);
101   
102          if (null === $data || !is_array($data)) {
103              throw new TokenResponseException('Unable to parse response: ' . $responseBody);
104          } elseif (isset($data['error'])) {
105              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
106          } elseif (!isset($data["oauth_token"]) || !isset($data["oauth_token_secret"])) {
107              throw new TokenResponseException('Invalid response. OAuth Token data not set: ' . $responseBody);
108          }
109   
110          $token = new StdOAuth1Token();
111   
112          $token->setRequestToken($data['oauth_token']);
113          $token->setRequestTokenSecret($data['oauth_token_secret']);
114          $token->setAccessToken($data['oauth_token']);
115          $token->setAccessTokenSecret($data['oauth_token_secret']);
116   
117          $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
118          unset($data['oauth_token'], $data['oauth_token_secret']);
119          $token->setExtraParams($data);
120   
121          return $token;
122      }
123  }
124