Abraham\TwitterOAuth\TwitterOAuth::oauth2 PHP Method

oauth2() public method

Make /oauth2/* requests to the API.
public oauth2 ( string $path, array $parameters = [] ) : array | object
$path string
$parameters array
return array | object
    public function oauth2($path, array $parameters = [])
    {
        $method = 'POST';
        $this->resetLastResponse();
        $this->response->setApiPath($path);
        $url = sprintf('%s/%s', self::API_HOST, $path);
        $request = Request::fromConsumerAndToken($this->consumer, $this->token, $method, $url, $parameters);
        $authorization = 'Authorization: Basic ' . $this->encodeAppAuthorization($this->consumer);
        $result = $this->request($request->getNormalizedHttpUrl(), $method, $authorization, $parameters);
        $response = JsonDecoder::decode($result, $this->decodeJsonAsArray);
        $this->response->setBody($response);
        return $response;
    }

Usage Example

Exemplo n.º 1
0
 public function Oauth()
 {
     $oauth = new TwitterOAuth($this->key, $this->secret);
     $accessToken = $oauth->oauth2('oauth2/token', ['grant_type' => 'client_credentials']);
     $twitter = new TwitterOAuth($this->key, $this->secret, null, $accessToken->access_token);
     return $twitter;
 }
All Usage Examples Of Abraham\TwitterOAuth\TwitterOAuth::oauth2