From 63921ac42a8f38c3abfc74348920741c3ef730c3 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Tue, 20 May 2014 21:30:22 -0700 Subject: [PATCH] Add Instagram example --- examples/instagram_popular_media.php | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples/instagram_popular_media.php diff --git a/examples/instagram_popular_media.php b/examples/instagram_popular_media.php new file mode 100644 index 0000000..c121314 --- /dev/null +++ b/examples/instagram_popular_media.php @@ -0,0 +1,57 @@ +post('https://api.instagram.com/oauth/access_token', array( + 'client_id' => INSTAGRAM_CLIENT_ID, + 'client_secret' => INSTAGRAM_CLIENT_SECRET, + 'grant_type' => 'authorization_code', + 'redirect_uri' => $redirect_uri, + 'code' => $code, + )); + + if ($curl->error) { + echo $curl->response->error_type . ': ' . $curl->response->error_message . '
'; + echo 'Try again?'; + exit; + } + + $_SESSION['access_token'] = $curl->response->access_token; +} + +if (isset($_SESSION['access_token'])) { + $curl = new Curl(); + $curl->get('https://api.instagram.com/v1/media/popular', array( + 'access_token' => $_SESSION['access_token'], + )); + foreach ($curl->response->data as $media) { + echo + '' . + '' . + ''; + } +} +else { + header('Location: https://api.instagram.com/oauth/authorize/?' . http_build_query(array( + 'client_id' => INSTAGRAM_CLIENT_ID, + 'redirect_uri' => $redirect_uri, + 'response_type' => 'code', + ))); + exit; +}