Gajus\Fuss\AccessToken::getCode PHP Method

getCode() public method

Get the code for the long-lived access token.
See also: https://developers.facebook.com/docs/facebook-login/access-tokens#long-via-code
public getCode ( ) : string
return string
    public function getCode()
    {
        if (!$this->isLong()) {
            throw new Exception\AccessTokenException('Short-lived access token cannot be used to get code.');
        }
        // The request must be made on behalf of the user (using user access_token).
        $user = new \Gajus\Fuss\User($this);
        // First we need to get the code using the long-lived access token.
        // @see https://developers.facebook.com/docs/facebook-login/access-tokens#long-via-code
        $request = new \Gajus\Fuss\Request($user, 'GET', 'oauth/client_code', ['client_id' => $this->app->getId(), 'client_secret' => $this->app->getSecret(), 'redirect_uri' => '']);
        $response = $request->make();
        return $response['code'];
    }

Usage Example

Esempio n. 1
0
 /**
  * @depends testExtendUserAccessToken
  */
 public function testExchangeLongLivedAccessTokenForCode(\Gajus\Fuss\AccessToken $access_token)
 {
     $this->assertTrue($access_token->isLong());
     return $access_token->getCode($access_token);
 }