Access Providers APIs
Once a user is authenticated with an OAuth1 or OAuth2 provider, and depending on the authorization given to your application, you should be able to query the that provider’s API in behalf of the connected user.
For this you can call the method
apiRequest on a connected adapter instance, and it’s defined as follows:
function apiRequest(string $url [, string $method [, array $parameters [, array $headers]]])
||string||Required: Relative or absolute url to API’s action.|
||string||Optional: HTTP method. It can be either GET or POST, and defaults to GET.|
||array||Optional: HTTP GET parameters or POST data as an associative array.|
||array||Optional: HTTP REQUEST Headers as an associative array.|
apiRequestis called. To know more about providers specs and capabilities, refer to Supported Providers .
Below is a simple example of how to access GitHub’s API.
//Instantiate GitHub's adapter $github = new Hybridauth\Provider\GitHub($config); //Authenticate the user $github->authenticate(); //Access GitHub API to retrieve the user's public gists. //See: https://developer.github.com/v3/gists/ $apiResponse = $github->apiRequest('gists'); // or absolute url: https://api.github.com/gists //Inspect API's response. var_dump($apiResponse);
Another simple example of how to access Twitter’s API.
//Instantiate Twitter's adapter $twitter = new Hybridauth\Provider\Twitter($config); //Authenticate the user $twitter->authenticate(); //Access Twitter's API to post a status update //See: https://dev.twitter.com/rest/reference/post/statuses/update $apiResponse = $twitter->apiRequest('statuses/update.json', 'POST', [ 'status' => 'This is tests!' ]); //Inspect API's response. var_dump($apiResponse);