├── fake_database.txt ├── config.php.sample ├── readme ├── api_config_setup.png └── fake_instagram.png ├── index.php ├── callback.php ├── view.php ├── README.md ├── http.php └── settings-functions.php /fake_database.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config.php.sample: -------------------------------------------------------------------------------- 1 | Instagram Basic Display Test"; 6 | 7 | $login_url = getLoginURL(); 8 | 9 | echo "$login_url"; 10 | -------------------------------------------------------------------------------- /callback.php: -------------------------------------------------------------------------------- 1 | "; 5 | 6 | // now let's see if we can read in our user 7 | $userData = file_get_contents('fake_database.txt'); 8 | 9 | $userData = json_decode($userData, true); 10 | 11 | // easier to just ensure that this exists 12 | if (!isset($userData["posts"])) { 13 | $userData["posts"] = array(); 14 | } 15 | 16 | $media = getMedia($userData["ig_access_token"], $userData["posts"]); 17 | 18 | // now let's save our "user" to the database 19 | $fake_user_data_array = array(); 20 | $fake_user_data_array["ig_user_id"] = $userData["ig_user_id"]; 21 | $fake_user_data_array["ig_access_token"] = $userData["ig_access_token"]; 22 | $fake_user_data_array["ig_access_token_last_updated"] = time(); 23 | $fake_user_data_array["posts"] = $media; 24 | writeJsonToFile($fake_user_data_array); 25 | 26 | foreach ($media as $media_item) { 27 | echo " 28 | 29 |
30 | \"...\" 31 |
32 |

".$media_item["caption"]."

33 |
34 |
35 | 36 | "; 37 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Instagram Basic Display API Simple Integration 2 | 3 | A simple PHP implementation of the [Instagram Basic Display API](https://developers.facebook.com/docs/instagram-basic-display-api) 4 | 5 | This implementation does the following: 6 | 7 | 1. index.php provides a link to authorize the implementation 8 | 2. If authorizes, we'll be taken back to /callback.php with an attached Oauth code 9 | 3. We then exchange the code, with a short-lived access token, then in the same step, we exchange that short-lived access token with a long-lived access token 10 | 4. Once we have our access tokens, we write a fake "user" to a very fake "database" 11 | 5. We redirect to view.php, where we look for new posts then display them 12 | 13 | ## File Structure 14 | 15 | 16 | | File | Description | 17 | | :------------- |:-------------| 18 | | callback.php | Part of Step 2, this function receieves the authorization code and starts the process of getting a long-lived token we can use to fetch the fun stuff| 19 | | config.php | This is where your APP ID, APP Secret, and Callback URLS are defined. See config.php.sample for example | 20 | | config.php.sample | ^ | 21 | | fake_database.txt | We're literally just writing JSON to a file. Like I said, it's a *very* simple integration | 22 | | http.php | Utility class to handle curl GET and POST requests. I re-use this class a lot | 23 | | index.php | Part of Step 1, this page provides the authorization URL to get started | 24 | | settings-functions.php | This is the beef of the program. Defines our API endpoints, make sure our configuration is intact, makes all API calls, and adds a few helper functions | 25 | | view.php | Part of Step 5, this would be like the "logged in" view and shows the retrieved users posts | 26 | 27 | 28 | 29 | ## Screenshots 30 | 31 | ### Config 32 | 33 | Set up config.php with variables from API setup 34 | 35 | ![alt text](https://raw.githubusercontent.com/christinabranson/Instagram-Basic-Display-API-Simple-Integration/master/readme/api_config_setup.png "Screenshot showing up to set up config.php") 36 | 37 | The final result 38 | 39 | ![alt text](https://raw.githubusercontent.com/christinabranson/Instagram-Basic-Display-API-Simple-Integration/master/readme/fake_instagram.png "Screenshot showing the final result") -------------------------------------------------------------------------------- /http.php: -------------------------------------------------------------------------------- 1 | getMessage()); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /settings-functions.php: -------------------------------------------------------------------------------- 1 | getMessage()); 155 | } 156 | } --------------------------------------------------------------------------------