Introducing the Instagram Graph API PHP SDK v1.0


In this post we are going to go over the Instagram Graph API PHP SDK! I created this SDK because interacting with the Instagram Graph API can be frustrating and confusing at times and I wanted to make it easier to make API calls and interact with the Instagram Graph API. This is an open source SDK aimed at making the Instagram Graph API easier to learn and use!

SDK Code Setup and Structure

The GitHub Repository is setup for the most part to mimic the Instagram Graph API Documentation. Each reference section in the documentation maps to a folder in the SDK.

Instagram Graph API Documentation to SDK
Instagram Graph API Documentation to SDK

Then inside each of those folders is a class for each endpoint. Inside each folder there is also a main class which all the other classes in the folder extent. The main classes in each folder also extend the master Instagram.php class which is in the root folder.

Instagram Graph API Documentation to SDK
Instagram Graph API Documentation to SDK

Installation

To install the SDK you can opt for the Composer route, or you can simply download the code from the github repo. Here are examples of both.

Composer

Run this command:

composer require jstolpe/instagram-graph-api-php-sdk

Require the autoloader.

require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

GitHub

git clone git@github.com:jstolpe/instagram-graph-api-php-sdk.git

Require the custom autoloader.

require_once '/instagram-graph-api-php-sdk/src/instagram/autoload.php'; // change path as needed

GET Request

Here is an example of a simple GET request for getting a user’s profile and media posts. All we have to do is pass along the Instagram User ID, username, and an access token.

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();

POST Request

Here is simple POST example of posting an image to an Instagram account. The variables we need for the config are the Instagram User ID and an access token. Then, when we are creating the image container we need to specify the caption for the post, and then a url to the image and the image must be on a public server.

use Instagram\User\Media;
use Instagram\User\MediaPublish;

$config = array( // instantiation config params
    'user_id' => 'USER_ID',
    'access_token' => 'ACCESS_TOKEN',
);

// instantiate user media
$media = new Media( $config );

$imageContainerParams = array( // container parameters for the image post
    'caption' => 'CAPTION', // caption for the post
    'image_url' => 'IMAGE_URL', // url to the image must be on a public server
);

// create image container
$imageContainer = $media->create( $imageContainerParams );

// get id of the image container
$imageContainerId = $imageContainer['id'];

// instantiate media publish
$mediaPublish = new MediaPublish( $config );

// post our container with its contents to instagram
$publishedPost = $mediaPublish->create( $imageContainerId );

CUSTOM Request

Here is an example of a custom request. The SDK allows you to fully specify the request type, endpoint, and parameters for the endpoint. Like all requests we first need an access token. Then we are ready to make our request (get/post/delete). Specify the endpoint to hit along with the parameters for the endpoint. The parameters array is key/value paired where the key must match what the IG API is expecting according to the documentation and you can add as many or as little as you need.

// 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',
        // ...
    )
) );

More Functionality

The Instagram Graph API PHP SDK covers and contains functionality for most of the Instagram Graph API endpoints. This post was a high level overview and in future blog posts I will cover specific endpoints in more detail. The GitHub Wiki contains documentation for the entire SDK with examples for how to call every endpoint.

Links

Code on GitHub

Wiki on GitHub

YouTube Video

That is going to do it for this post! Leave any comments/questions below and thanks for stopping by the blog!

1236 comments

  1. Howdy, I doo tthink you bpog could bee having weeb browser compatibility issues.
    Whhen I take a look att yourr blog iin Safari, it looks fne however, when openkng iin IE, iit has sone overllapping issues.

    I mereely wanted tto give you a quicfk heads up!
    Apart froom that, great site!

  2. Yet another thing to mention is that an online business administration training course is designed for individuals to be able to efficiently proceed to bachelors degree programs. The 90 credit diploma meets the lower bachelor college degree requirements then when you earn your own associate of arts in BA online, you may have access to up to date technologies in this particular field. Some reasons why students want to get their associate degree in business is because they can be interested in the field and want to get the general education and learning necessary just before jumping right bachelor college diploma program. Thanks alot : ) for the tips you actually provide in your blog.

  3. DreamProxies – Most affordable USA Private Proxies: Elite top quality, Unrestricted bandwith, 1000 mb/s superspeed, 99,9 uptime, Not continuous IP’s, Virtually no utilization limits, A number of subnets, USA or maybe The european countries proxies – Invest in At this moment – https://DreamProxies.com

  4. Great post. I was checking continuously this blog and I am impressed!
    Very useful info particularly the last part 🙂
    I care for such information much. I was seeking this certain info for a very long time.
    Thank you and good luck.

  5. This design is spectacular! You obviously know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!

  6. Having read this I thought it was very informative. I appreciate you taking the time and energy to put this short article together. I once again find myself spending a lot of time both reading and posting comments. But so what, it was still worthwhile!

  7. I was wondering if you ever considered changing the page layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or two pictures. Maybe you could space it out better?

  8. Hi there just wanted to give you a quick heads up. The words in your article seem to be running off the screen in Firefox. I’m not sure if this is a format issue or something to do with browser compatibility but I figured I’d post to let you know. The design look great though! Hope you get the issue solved soon. Cheers

  9. Having read this I believed it was rather informative. I appreciate you spending some time and effort to put this informative article together. I once again find myself personally spending way too much time both reading and leaving comments. But so what, it was still worthwhile!

  10. Excellent post. I used to be checking constantly this blog and I’m inspired! Extremely useful info particularly the ultimate part 🙂 I take care of such info a lot. I was looking for this particular information for a very lengthy time. Thank you and good luck.

  11. It’s really a great and helpful piece of information. I am glad that you shared this helpful info with us. Please keep us informed like this. Thank you for sharing.

  12. I’m really loving the theme/design of your site. Do you ever run into any web browser compatibility issues? A small number of my blog audience have complained about my blog not operating correctly in Explorer but looks great in Safari. Do you have any advice to help fix this issue?

  13. Hello are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and create my own. Do you require any html coding expertise to make your own blog? Any help would be greatly appreciated!

  14. Hello very nice web site!! Man .. Excellent .. Wonderful .. I will bookmark your site and take the feeds additionally? I am glad to search out numerous useful info here in the submit, we’d like develop more strategies in this regard, thanks for sharing. . . . . .

  15. Simply desire to say your article is as astonishing. The clearness on your submit is simply cool and that i could assume you are an expert on this subject. Fine together with your permission allow me to grab your RSS feed to keep updated with impending post. Thanks 1,000,000 and please continue the gratifying work.

  16. I blog quite often and I seriously appreciate your information. This great article has really peaked my interest. I’m going to take a note of your website and keep checking for new information about once per week. I opted in for your Feed too.

  17. Hello! This is kind of off topic but I need some advice from an established blog. Is it very difficult to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about setting up my own but I’m not sure where to start. Do you have any tips or suggestions? Cheers

  18. Thanks for ones marvelous posting! I quite enjoyed reading it, you could be a great author. I will ensure that I bookmark your blog and definitely will come back at some point. I want to encourage one to continue your great writing, have a nice weekend!

  19. Excellent items from you, man. I have be mindful your stuff previous to and you’re just too excellent. I actually like what you have received here, certainly like what you’re stating and the best way in which you are saying it. You are making it enjoyable and you still take care of to stay it smart. I can’t wait to learn much more from you. That is really a tremendous web site.

  20. Howdy very cool website!! Guy .. Excellent .. Superb .. I’ll bookmark your blog and take the feeds additionally? I am glad to search out so many useful information here in the submit, we want work out extra strategies on this regard, thank you for sharing. . . . . .

  21. Having read this I believed it was very informative. I appreciate you spending some time and energy to put this informative article together. I once again find myself spending a significant amount of time both reading and leaving comments. But so what, it was still worth it!

  22. Undeniably believe that which you stated. Your favorite reason seemed to be on the web the simplest thing to be aware of. I say to you, I certainly get irked while people think about worries that they plainly do not know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people can take a signal. Will likely be back to get more. Thanks

  23. Hey, I think your blog might be having browser compatibility issues. When I look at your blog site in Firefox, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, very good blog!

  24. Howdy just wanted to give you a brief heads up and let you know a few of the images aren’t loading correctly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same results.

  25. Hey there just wanted to give you a quick heads up. The words in your article seem to be running off the screen in Ie. I’m not sure if this is a formatting issue or something to do with browser compatibility but I figured I’d post to let you know. The design look great though! Hope you get the problem solved soon. Thanks

  26. I’m really enjoying the design and layout of your site. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Exceptional work!

  27. hello there and thank you for your info – I’ve certainly picked up anything new from right here. I did however expertise some technical points using this website, since I experienced to reload the website a lot of times previous to I could get it to load properly. I had been wondering if your hosting is OK? Not that I am complaining, but slow loading instances times will often affect your placement in google and can damage your high-quality score if ads and marketing with Adwords. Well I’m adding this RSS to my e-mail and could look out for a lot more of your respective exciting content. Make sure you update this again very soon.

  28. Hi there! This blog post could not be written any better! Going through this post reminds me of my previous roommate! He continually kept preaching about this. I am going to forward this article to him. Pretty sure he’ll have a good read. I appreciate you for sharing!

  29. We’re a group of volunteers and starting a brand new scheme in our community. Your web site offered us with helpful info to work on. You’ve done a formidable process and our whole community shall be thankful to you.

  30. Magnificent goods from you, man. I’ve understand your stuff previous to and you’re just extremely magnificent. I really like what you’ve acquired here, really like what you are stating and the way in which you say it. You make it entertaining and you still take care of to keep it wise. I cant wait to read far more from you. This is really a terrific website.

  31. Thank you a lot for sharing this with all people you actually understand what you are talking about! Bookmarked. Kindly additionally seek advice from my site =). We could have a link alternate arrangement among us

  32. Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a little bit, but instead of that, this is great blog. A fantastic read. I’ll definitely be back.

  33. Hi! This is kind of off topic but I need some help from an established blog. Is it tough to set up your own blog? I’m not very techincal but I can figure things out pretty fast. I’m thinking about setting up my own but I’m not sure where to begin. Do you have any points or suggestions? Cheers

  34. I just couldn’t depart your web site before suggesting that I really enjoyed the standard information an individual provide to your visitors? Is going to be back ceaselessly in order to check up on new posts

  35. Heya i am for the first time here. I found this board and I find It really useful & it helped me out a lot. I hope to present something back and help others such as you aided me.

  36. Definitely believe that which you stated. Your favorite justification seemed to be on the net the easiest thing to be aware of. I say to you, I definitely get annoyed while people consider worries that they plainly do not know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks

  37. You really make it seem really easy along with your presentation but I to find this matter to be really something which I believe I would never understand. It seems too complex and very wide for me. I’m having a look forward for your next submit, I’ll attempt to get the hold of it!

  38. Its such as you read my mind! You seem to know a lot approximately this, like you wrote the guide in it or something. I think that you simply can do with a few percent to power the message home a little bit, however other than that, that is excellent blog. A fantastic read. I’ll certainly be back.

  39. Superb site you have here but I was wanting to know if you knew of any discussion boards that cover the same topics talked about here? I’d really love to be a part of community where I can get suggestions from other knowledgeable individuals that share the same interest. If you have any suggestions, please let me know. Kudos!

  40. I am not sure where you are getting your info, but great topic. I needs to spend some time learning much more or understanding more. Thanks for great info I was looking for this info for my mission.

  41. Thanks for your marvelous posting! I genuinely enjoyed reading it, you’re a great author. I will make certain to bookmark your blog and definitely will come back later on. I want to encourage you to definitely continue your great job, have a nice evening!

  42. I believe what you published was very reasonable. But, consider this, suppose you typed a catchier title? I ain’t saying your information is not solid., but what if you added a title that makes people want more? I mean %BLOG_TITLE% is a little vanilla. You ought to peek at Yahoo’s home page and note how they create article headlines to get people interested. You might try adding a video or a picture or two to grab people interested about everything’ve got to say. Just my opinion, it might make your posts a little livelier.

  43. Whats up very cool site!! Guy .. Excellent .. Amazing .. I’ll bookmark your site and take the feeds additionally? I’m glad to find a lot of helpful information here within the post, we’d like develop extra strategies in this regard, thanks for sharing. . . . . .

  44. Hi! I know this is sort of off-topic however I had to ask. Does running a well-established website such as yours take a large amount of work? I am completely new to running a blog but I do write in my diary every day. I’d like to start a blog so I will be able to share my experience and thoughts online. Please let me know if you have any kind of ideas or tips for brand new aspiring bloggers. Appreciate it!

  45. Thanks for ones marvelous posting! I actually enjoyed reading it, you could be a great author.I will be sure to bookmark your blog and will come back later in life. I want to encourage you to ultimately continue your great writing, have a nice weekend!

  46. Definitely believe that which you said. Your favorite justification appeared to be on the net the simplest thing to be aware of. I say to you, I certainly get annoyed while people consider worries that they plainly don’t know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people can take a signal. Will probably be back to get more. Thanks

  47. Greetings from Idaho! I’m bored to death at work so I decided to check out your website on my iphone during lunch break. I really like the information you present here and can’t wait to take a look when I get home. I’m amazed at how quick your blog loaded on my mobile .. I’m not even using WIFI, just 3G .. Anyhow, excellent blog!

  48. My partner and I absolutely love your blog and find the majority of your post’s to be exactly what I’m looking for. Does one offer guest writers to write content to suit your needs? I wouldn’t mind writing a post or elaborating on some of the subjects you write with regards to here. Again, awesome web site!

  49. Do you have a spam issue on this blog; I also am a blogger, and I was curious about your situation; we have developed some nice practices and we are looking to swap solutions with other folks, be sure to shoot me an email if interested.

  50. Hi, i read your blog from time to time and i own a similar one and i was just curious if you get a lot of spam feedback? If so how do you protect against it, any plugin or anything you can suggest? I get so much lately it’s driving me insane so any assistance is very much appreciated.

  51. This design is incredible! You obviously know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!

  52. Excellent beat ! I wish to apprentice even as you amend your site, how could i subscribe for a blog site? The account helped me a applicable deal. I had been tiny bit familiar of this your broadcast offered bright clear concept

  53. I feel this is one of the such a lot significant information for me. And i am satisfied reading your article. However want to statement on some basic things, The website style is ideal, the articles is really great : D. Good process, cheers

  54. You really make it appear really easy with your presentation but I to find this topic to be really something that I feel I might never understand. It seems too complicated and extremely huge for me. I’m looking ahead in your subsequent post, I’ll attempt to get the hang of it!

  55. I’m not that much of a internet reader to be honest but your sites really nice, keep it up! I’ll go ahead and bookmark your site to come back in the future. Many thanks

  56. Howdy! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us useful information to work on. You have done a wonderful job!

  57. Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit, but other than that, this is great blog. An excellent read. I will certainly be back.

  58. Magnificent goods from you, man. I’ve understand your stuff previous to and you are just too excellent. I actually like what you’ve acquired here, really like what you are saying and the way in which you say it. You make it entertaining and you still take care of to keep it sensible. I cant wait to read much more from you. This is really a great web site.

  59. I like the helpful information you provide in your articles. I’ll bookmark your blog and check again right here frequently. I am moderately sure I will be told many new stuff right here! Good luck for the following!

  60. Howdy! I could have sworn I’ve been to your blog before but after going through many of the articles I realized it’s new to me. Anyways, I’m definitely happy I discovered it and I’ll be bookmarking it and checking back frequently!

  61. Hey would you mind stating which blog platform you’re using? I’m looking to start my own blog soon but I’m having a hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique. P.S My apologies for getting off-topic but I had to ask!

  62. Hey there! I know this is kinda off topic however , I’d figured I’d ask. Would you be interested in exchanging links or maybe guest authoring a blog post or vice-versa? My site goes over a lot of the same topics as yours and I believe we could greatly benefit from each other. If you are interested feel free to shoot me an e-mail. I look forward to hearing from you! Terrific blog by the way!

  63. Hello! I could have sworn I’ve been to this website before but after reading through some of the post I realized it’s new to me. Anyhow, I’m definitely delighted I found it and I’ll be book-marking and checking back frequently!

  64. Do you have a spam issue on this blog; I also am a blogger, and I was curious about your situation; many of us have created some nice practices and we are looking to trade methods with others, please shoot me an e-mail if interested.

Leave a Reply

Your email address will not be published. Required fields are marked *