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 [, bool $multipart]]]])
Parameter Type Description
$url string Required: Relative or absolute url to API’s action.
$method string Optional: HTTP method. It can be either GET or POST, and defaults to GET.
$parameters array Optional: HTTP GET parameters or POST data as an associative array.
$headers array Optional: HTTP REQUEST Headers as an associative array.
$multipart bool Optional: If HTTP request should be sent as multipart/form-data, used when uploading images/videos
OpenID being a decentralized authentication protocol and not an authorization standard, its adapters do not communicate with providers APIs and therefore you cannot perform any action in behalf of authenticated user, and Hybridauth will throw NotImplementedException when apiRequest is 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

// Access GitHub API to retrieve the user's public gists.
// See:
$apiResponse = $github->apiRequest('gists'); // or absolute url:

// Inspect API's response.

Another simple example of how to access Twitter’s API.

// Instantiate Twitter's adapter
$twitter = new Hybridauth\Provider\Twitter($config);

// Authenticate the user

// Access Twitter's API to post a status update
// See:
$apiResponse = $twitter->apiRequest('statuses/update.json', 'POST', ['status' => 'This is tests!']);

// Inspect API's response.

Below is an example for uploading a video to a Facebook Page.

// Instantiate Facebook's adapter
$facebook = new Hybridauth\Provider\Facebook($config);

// Authenticate the user

// Access Facebook's API to post a video
// See:
                          'title' => $videoTitle,
                          'description' => $videoDescription,
                          'source' => new \CURLFile($videoPath),

// Inspect API's response.