/** * @param string $endpoint endpoint * @param array $parameters parameters */ protected function addOAuthParameters($endpoint, array &$parameters) { $accessToken = $this->metadata->getAccessToken(); $accessTokenSecret = $this->metadata->getAccessTokenSecret(); if (empty($accessToken) || empty($accessTokenSecret)) { throw new \LogicException('Cannot access this resource without oauth authentication.'); } $parameters['oauth_consumer_key'] = $this->metadata->getApiKey(); $parameters['oauth_timestamp'] = time(); $parameters['oauth_nonce'] = md5(uniqid(rand(), true)); $parameters['oauth_signature_method'] = "HMAC-SHA1"; $parameters['oauth_version'] = "1.0"; $parameters['oauth_token'] = $accessToken; $parameters['oauth_signature'] = $this->buildOAuthSignature($endpoint, $parameters); }
/** * * @param string $apiInfoPath * @param string $tokenPath * @return FlickrApiClient */ public static function getClient($apiInfoPath, $tokenPath) { $apiKeys = json_decode(file_get_contents($apiInfoPath)); $metadata = new Metadata($apiKeys->apiKey, $apiKeys->apiSecret); $factory = new AuthApiFactory($metadata, new ExtendedGuzzleAdapter()); if (file_exists($tokenPath)) { $token = json_decode(file_get_contents($tokenPath)); $metadata->setOauthAccess($token->token, $token->secret); } else { $authUrl = $factory->createAuthUrl(); printf("Open the following link in your browser:\n%s\n", $authUrl); print 'Enter verification code: '; $authCode = trim(fgets(STDIN)); $factory->authenticate($authCode); $token = new \stdClass(); $token->token = $metadata->getAccessToken(); $token->secret = $metadata->getAccessTokenSecret(); file_put_contents($tokenPath, json_encode($token)); } return new FlickrApiClient($factory); }