DEV Community

Cover image for Distinguish between Business and Creators with the Instagram Graph API
Andrea Olivato
Andrea Olivato

Posted on

Distinguish between Business and Creators with the Instagram Graph API

TL;DR: Use Try/Catch on an empty Content Publishing call and look for a specific exception code to differentiate between Business and Creators accounts.

If you use the new Instagram Graph API (not to be confused with the Instagram Basic Display API) you know that these APIs can be used by Instagram Business Accounts and Creators Accounts.

Until recently, the difference between the two didn’t matter as much, since most features are available to both groups. However, when the new Instagram Content Publishing Api was released, Facebook made it only available for Business Accounts, not Creators.

This means that an Instagram Creator can Log In via Facebook and allow the permission for Content Publishing; but when you actually try to publish the content on their page, the API will throw an exception, saying that the user is not allowed to do so.

The main concern we encountered for Lnk.Bio is that we need to immediately inform the user that they won’t be able to use this specific feature. Otherwise they might start scheduling the posts for the future and we wouldn’t actually be able to publish them.

At first, we thought this information would be readily available within the IG User object, returned when you query the Instagram Graph API asking information about the logged user. However this endpoint doesn’t contain any information about the account type (Business/Creator). What makes this even stranger is that instead the Instagram Basic Display API provide this information in the account_type field of the User Object. The returned value can be one of BUSINESS, MEDIA_CREATOR, or PERSONAL, which is exactly what we were looking for. I can’t really find a reason why this is available in the Basic Display API and not the Graph API.

Looking at StackOverflow it looked like the most common approach for the Graph API is to scrape the user profile, since this information is published in the page JSON. But this is of course not allowed by Instagram T&C and is also not a solid solution, as it would be subject to network pitfalls, page errors, and also Instagram anti-crawler policy that would block your IPs after too many requests. So this was a no go.

In the end the best solution we found is to perform an empty POST request simulating the publishing of an Instagram content to the connected account, catch the exception and look for a specific Exception Code 10 in order to identify the type of account.

In order not to actually publish or create anything on the user account, you can perform an empty call (POST method without any POST data) to the /userid/media endpoint. Then catch the FacebookResponseException and look for the code=10.

In PHP code:

public function isBusiness() {
    try {
        $this->conn->post("/".$this->fb_id."/media", [], $this->getToken());
        return true;
    } catch (FacebookResponseException $e) {
        if ($e->getCode() == 10) {
        return false;
    } catch (\Exception $e) {
        return true;
Enter fullscreen mode Exit fullscreen mode

As you can see from the code above, all other exceptions are interpreted as Business Account, while only the Exception with code 10 is interpreted as Creator Account.

If you have a better approach to this without performing any call, let me know in the comments!

Top comments (0)