Skip to content

Instantly share code, notes, and snippets.

@joeyz
Created March 21, 2015 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeyz/3ec897da3ecdd08a723a to your computer and use it in GitHub Desktop.
Save joeyz/3ec897da3ecdd08a723a to your computer and use it in GitHub Desktop.
json to php object
<?php
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$result = fetchData("https://api.instagram.com/v1/users/ID-GOES-HERE/media/recent/?access_token=TOKEN-GOES-HERE");
$result = json_decode($result);
foreach ($result->data as $post) {
// Do something with this data.
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment