-
Notifications
You must be signed in to change notification settings - Fork 31
Custom Params
Justin Stolpe edited this page May 21, 2022
·
8 revisions
The Instagram Graph API PHP SDK allows for you to specify custom params. By default, the SDK tries to return all possible fields and parameters for all endpoints. If, for whatever reason, you want to make your own request or specify certain parameters, you can.
The getSelf() will return all possible parameters and fields for an endpoint. However, you can pass an array into any getSelf() function call to specify certain parameters. The key value pair in the custom params passed in must match the required key values expected by the Instagram Graph API.
/**
* Custom params array structure is very important. The key must match what Instagram Graph API
* is expecting as the parameter name. The value must also match what the Instagram Graph API
* is expecting for the given key.
*
* Example Instagram Graph API "https://url-to-endpoint/?<KEY1>=<VALUE1>&<KEY2>=<VALUE2>&..."
* To override default values with the sdk, your custom params array you pass to getSelf()
* would look like this.
*/
$params = array(
'<KEY1>' => '<VALUE1>',
'<KEY2>' => '<VALUE2>'.
// ...
);
$response = $class->getSelf( $params );
/**
* Here is a real example call for business discovery getSelf(). Instead of defaulting to return all
* the fields, we are only requesting the username and profile picture. With this custom params
* array, when the SDK makes the call to the endpoint, it would look like this:
*
* "https://url-to-endpoint/?fields=business_discovery.username(<USERNAME>){username,profile_picture_url}"
*/
$params = array( // key/value pairs must match what the Instagram Graph API expects
'fields' => 'business_discovery.username(<USERNAME>){username,profile_picture_url}'
);
$userBusinessDiscovery = $businessDiscovery->getSelf( $params );