Codementor Events

Integration: Connect & Manage Instagram Accounts via Facebook Graph API

Published Jun 29, 2019

I recently had a chance to integrate Facebook Graph API to connect Instagram (IG) accounts in order to manage IG accounts. For Business managers it is very important that they have tools, proper interface to manage the IG accounts easily.

So before we dive in, please understand there are some limitations to use the API, you will have to go through the review process and will have to verify your business by providing proper documentation. Official API for IG no longer accepts app requests for review. So Facebook Graph API is the only way to go with now.

Limitations:

  • The API cannot be used to access non-Business or non-Creator Instagram accounts. If you are building apps for non-Business or non-Creator Instagram users, use the Instagram Platform API instead.
  • Currently, Business Discovery only returns data about Instagram Business Users.
  • Content Publishing can only be used on behalf of Instagram Business Users.

Permissions:
There are multiple permissions to look at based on use case. I will be using instagram_basic to get metadata. Here are all the permissions graph API offers:

  • instagram_basic
  • instagram_content_publish
  • instagram_manage_comments
  • instagram_manage_insights
  • manage_pages or pages_show_list
  • Instagram Public Content Access

Getting Started:
You will need access to the following:

  • An Instagram Business Account or Instagram Creator Account
  • A Facebook Page connected to that account
  • A Facebook Developer account that can perform Tasks on that Page
  • A registered Facebook App with Basic settings configured

Now right to the steps to integrate Graph API.

  1. Setup a basic project, for this article a PHP project.
  2. Now Install Official Facebook SDK. I created everything in PHP so link to Facebook's PHP SDK is https://github.com/facebook/php-graph-sdk. You can use composer to install it.
  3. Once installed, download following wrapper I have created to make it easier to make calls to graph API and handle request and response. Once downloaded, include it in the project. Make sure to fill in app ID, app secret and redirect url in it. https://gist.github.com/abhij89/f409b4ae91bfc228cb66c78a1b969131
  4. Now create a file, and put following content in it:
<?php 
 include('InstagramGraphLogin.php'); 
 $instagramLogin = new InstagramSocial(); 
 $instagramLoginUrl = $instagramLogin->getLoginUrl(); // include the wrapper
?>
 <a href="<?php echo $instagramLoginUrl; ?>" class="btn btn-social btn-instagram">Connect Instagram</a> <!-- Login Authentication URL for Facebook -->

This will put a simple button which will take you to Facebook for login authentication and asking you to grant permissions to our app to manage Instagram Accounts.
Note: Instagram account should be connected to one of the Facebook page for this to work. Go to your Facebook page settings, click on Instagram from sidebar and connect IG account. Following image shows how:
connectInstagram.png
5. Create another file which will handle the response once user authenticates our app. Put following content in the same:

<?php 
include('InstagramGraphLogin.php'); 
$instagramLogin = new InstagramSocial();
$connectedAccountsData = $instagramSocial->getUserInfo(); // returns basic metadata for connected IG accounts

echo "<pre>"; print_r(  $connectedAccountsData );
// Do something with the data
  1. You're done.

Easy enough.

Here is a official documentation from Facebook: https://developers.facebook.com/docs/instagram-api/getting-started

Issue I ran in while working it out: https://github.com/facebook/php-graph-sdk/issues/1126

Originally posted here: https://blog.staginginstance.com/integration-connect-manage-instagram-accounts-via-facebook-graph-api/

Discover and read more posts from Abhishek jain
get started
post comments3Replies
Mia Lee
9 months ago

Sounds like a fantastic opportunity, and I discovered it on Instagram. I feel that social networks provide a lot of opportunities. For me, the most important thing is to have high-quality followers and views, and I’m not interested in bots that will not generate a profit for my business. Recently, I needed to buy Instagram views with PayPal. And this significantly increased the interest and reach of my account and personal brand.

Diter Knobloch
a year ago

Hey there! For those of us who adore staying in the loop about celebrities, read the details here . It has become my ultimate destination for all the captivating updates on Jem Wolfie. Believe me, it’s an absolute essential for every fan out there.

Gary Stokley
2 years ago

One of my favorite social media networks is Instagram. Although I attempt to employ them all to maximize the effectiveness of my business. But, the coverage has recently decreased dramatically, which is why I started using this service https://likesai.com/buy-instagram-likes/ I require real and high-quality followers and likes and I can always count on it.