[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace OAuth\OAuth1\Service; 4 5 use OAuth\OAuth1\Signature\SignatureInterface; 6 use OAuth\OAuth1\Token\StdOAuth1Token; 7 use OAuth\Common\Http\Exception\TokenResponseException; 8 use OAuth\Common\Http\Uri\Uri; 9 use OAuth\Common\Consumer\CredentialsInterface; 10 use OAuth\Common\Http\Uri\UriInterface; 11 use OAuth\Common\Storage\TokenStorageInterface; 12 use OAuth\Common\Http\Client\ClientInterface; 13 14 class Flickr extends AbstractService 15 { 16 17 public function __construct( 18 CredentialsInterface $credentials, 19 ClientInterface $httpClient, 20 TokenStorageInterface $storage, 21 SignatureInterface $signature, 22 UriInterface $baseApiUri = null 23 ) { 24 parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri); 25 if ($baseApiUri === null) { 26 $this->baseApiUri = new Uri('https://api.flickr.com/services/rest/'); 27 } 28 } 29 30 public function getRequestTokenEndpoint() 31 { 32 return new Uri('https://www.flickr.com/services/oauth/request_token'); 33 } 34 35 public function getAuthorizationEndpoint() 36 { 37 return new Uri('https://www.flickr.com/services/oauth/authorize'); 38 } 39 40 public function getAccessTokenEndpoint() 41 { 42 return new Uri('https://www.flickr.com/services/oauth/access_token'); 43 } 44 45 protected function parseRequestTokenResponse($responseBody) 46 { 47 parse_str($responseBody, $data); 48 if (null === $data || !is_array($data)) { 49 throw new TokenResponseException('Unable to parse response.'); 50 } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] != 'true') { 51 throw new TokenResponseException('Error in retrieving token.'); 52 } 53 return $this->parseAccessTokenResponse($responseBody); 54 } 55 56 protected function parseAccessTokenResponse($responseBody) 57 { 58 parse_str($responseBody, $data); 59 if ($data === null || !is_array($data)) { 60 throw new TokenResponseException('Unable to parse response.'); 61 } elseif (isset($data['error'])) { 62 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 63 } 64 65 $token = new StdOAuth1Token(); 66 $token->setRequestToken($data['oauth_token']); 67 $token->setRequestTokenSecret($data['oauth_token_secret']); 68 $token->setAccessToken($data['oauth_token']); 69 $token->setAccessTokenSecret($data['oauth_token_secret']); 70 $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES); 71 unset($data['oauth_token'], $data['oauth_token_secret']); 72 $token->setExtraParams($data); 73 74 return $token; 75 } 76 77 public function request($path, $method = 'GET', $body = null, array $extraHeaders = array()) 78 { 79 $uri = $this->determineRequestUriFromPath('/', $this->baseApiUri); 80 $uri->addToQuery('method', $path); 81 82 $token = $this->storage->retrieveAccessToken($this->service()); 83 $extraHeaders = array_merge($this->getExtraApiHeaders(), $extraHeaders); 84 $authorizationHeader = array( 85 'Authorization' => $this->buildAuthorizationHeaderForAPIRequest($method, $uri, $token, $body) 86 ); 87 $headers = array_merge($authorizationHeader, $extraHeaders); 88 89 return $this->httpClient->retrieveResponse($uri, $body, $headers, $method); 90 } 91 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |