Last active
October 10, 2021 07:42
-
-
Save stefanRepac/7aaa1a5bb44f68d8fd6fb393596144ff to your computer and use it in GitHub Desktop.
Get Instagram API SINGLE Post with OEmbed in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- IMPORTANT!!! If you want to use OEmbed like this your Instagram profile MUST BE PUBLIC --> | |
| <?php | |
| // Using curl because if you use file_get_contents() it need more then 10s page to be loaded... | |
| function curl_get_contents($url) { | |
| // Initiate the curl session | |
| $ch = curl_init(); | |
| // Set the URL | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| // Removes the headers from the output | |
| curl_setopt($ch, CURLOPT_HEADER, 0); | |
| // Return the output instead of displaying it directly | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| // Execute the curl session | |
| $output = curl_exec($ch); | |
| // Close the curl session | |
| curl_close($ch); | |
| // Return the output as a variable | |
| return $output; | |
| } | |
| $single_json_object = curl_get_contents('https://api.instagram.com/oembed/?callback=&url=YOUR_INSTA_POST_URL'); | |
| $single_decode = json_decode($single_json_object,true); | |
| // Convert stdClass Objects to Multidimensional Arrays function https://gist.github.com/Soullighter/3362c72012e9cd9e22bd54bd2402b0cc | |
| $single_array = objectToArray($single_decode); | |
| // Display title of post | |
| echo $single_array['title']; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment