Skip to content

IG User Business Discovery

Justin Stolpe edited this page Sep 17, 2022 · 7 revisions

Get info and posts on other Instagram business and creator accounts.

YouTube Tutorial

Default Request

By default the SDK tries to return all fields possible for the endpoint.

use Instagram\User\BusinessDiscovery;

$config = array( // instantiation config params
    'user_id' => '<IG_USER_ID>',
    'username' => '<USERNAME>', // string of the Instagram account username to get data on
    'access_token' => '<ACCESS_TOKEN>',
);

// instantiate business discovery for a user
$businessDiscovery = new BusinessDiscovery( $config );

// initial business discovery
$userBusinessDiscovery = $businessDiscovery->getSelf();

Custom Requests

If there is specific information you want, simply make a custom request and pass along the parameters you want to the getSelf() function.

use Instagram\User\BusinessDiscovery;

$config = array( // instantiation config params
    'user_id' => '<IG_USER_ID>',
    'username' => '<USERNAME>', // string of the Instagram account username to get data on
    'access_token' => '<ACCESS_TOKEN>',
);

// instantiate business discovery for a user
$businessDiscovery = new BusinessDiscovery( $config );

$params = array( // custom params for the endpoint
    // example fields string "business_discovery.username(' . $config['username'] . '){username,media_count,media{id,caption,children{id,media}}}"
    'fields' => '<FIELDS_STRING>'
);

// initial business discovery
$userBusinessDiscovery = $businessDiscovery->getSelf( $param );

Pagination

The Instagram Graph API does not return all posts in one response but it will let us know if there are previous and next pages. The SDK takes care of building the links behind the scenes so all you need to do to get previous and next pages is make sure they exist and then call the getMediaPage() function.

use Instagram\User\BusinessDiscovery;
use Instagram\Request\Params;

$config = array( // instantiation config params
    'user_id' => '<IG_USER_ID>',
    'username' => '<USERNAME>', // string of the Instagram account username to get data on
    'access_token' => '<ACCESS_TOKEN>',
);

// instantiate business discovery for a user
$businessDiscovery = new BusinessDiscovery( $config );

// initial business discovery
$userBusinessDiscovery = $businessDiscovery->getSelf();

if ( $businessDiscovery->pagingNextLink ) { // get next page
    $nextPage = $businessDiscovery->getMediaPage( Params::NEXT );
}

if ( $businessDiscovery->pagingPreviousLink ) { // get prev page
    $prevPage = $businessDiscovery->getMediaPage( Params::PREV );
}
Clone this wiki locally