/** * Get the Oauth Access Token of a user from callback code * * @param string $code - Oauth2 Code returned with callback url after successfull login * * @return InstagramOAuth */ public function oauth($code) { $options = ['grant_type' => 'authorization_code', 'client_id' => $this->app->getId(), 'client_secret' => $this->app->getSecret(), 'redirect_uri' => $this->getCallbackUrl(), 'code' => $code, 'state' => $this->state]; $response = HelperFactory::getInstance()->request($this->client, Constants::API_TOKEN, $options, 'POST'); $this->oauthResponse = new InstagramOAuth(json_decode($response->getBody()->getContents())); return $this->oauthResponse; }
/** * Secure API Request by using endpoint, paramters and API secret * * @see https://www.instagram.com/developer/secure-api-requests/ * * @param InstagramApp $app * @param string $endpoint * @param array $params * * @return string (Signature) */ public static function generateSignature(InstagramApp $app, $endpoint, $params) { $signature = $endpoint; ksort($params); foreach ($params as $key => $value) { $signature .= "|{$key}={$value}"; } return hash_hmac('sha256', $signature, $app->getSecret(), false); }