Skip to content

Custom API Calls

Justin Stolpe edited this page May 21, 2022 · 4 revisions

The Instagram Graph API PHP SDK allows for fully customizable request.

Structure

// first we have to instantiate the core Instagram class with our access token
$instagram = new Instagram\Instagram( array(
    'access_token' => '<ACCESS_TOKEN>'
) );

/**
 * Here we are making our request to instagram and specify the endpoint along with our custom params.
 * There is a custom function for get, post, and delete.
 *     $instagram->get()
 *     $instagram->post()
 *     $instagram->delete()
 *
 * Here is the skeleton for the customized call.
 */
$response = $instagram->method( array(
    'endpoint' => '/<ENDPOINT>',
    'params' => array( // query params key/values must match what IG API is expecting for the endpoint
        '<KEY>' => '<VALUE>',
        '<KEY>' => '<VALUE>',
        // ...
    )
) );

Example Business Discovery

// first we have to instantiate the core Instagram class
$instagram = new Instagram\Instagram( array(
    'access_token' => '<ACCESS_TOKEN>'
) );

// here we are making our get request and specify the endpoint along with our custom params
$businessDiscovery = $instagram->get( array(
    'endpoint' => '/<IG_USER_ID>', // endpoint must match what the 
    'params' => array(
        'fields' => 'business_discovery.username(<USERNAME>){username,website}'
    )
) );
Clone this wiki locally