/** * @param string $endpoint endpoint * @param array $parameters parameters * * @return string */ protected function buildOAuthSignature($endpoint, array $parameters) { ksort($parameters); $uri = 'POST&' . rawurlencode($endpoint) . '&'; $params = ''; foreach ($parameters as $key => $value) { if (!in_array($key, self::$unsignedKeys)) { $params .= $key . '=' . rawurlencode($value) . '&'; } } $uri .= rawurlencode(substr($params, 0, -1)); return base64_encode(hash_hmac('sha1', $uri, $this->metadata->getSecret() . '&' . $this->metadata->getAccessTokenSecret(), true)); }
/** * * @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); }