티스토리 뷰
http://www.blueprintinteractive.com/blog/how-instagram-api-fancybox-simplified
Authentication
The first thing we need is an access token. Instagram uses OAuth 2.0 protocol for simple, but effective authentication. I could tell you how to retrieve access tokens but then I'd have to kill you (And everything I've done is documented on Instagram's Developer page). Instead, to make your lives easier, I've provided an easy way for you to attain your access token and user id. Click here to retrieve your access token and user ID.
Instagram has a 5000 request per hour rate limit. This is high in comparison to twitter and similar services so bundling requests to avoid the hitting the limit may not be necessary unless you have high volumes of traffic.
Retrieve Images
Now we are ready to get our images. See the code below to make this happen. In our example, we are using PHP's CURL library to make our requests.
- <?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.
- }
- ?>
The Final Product
This uses my Instagram account. As you can see, I pretty much never use it. Click on one of the images below to see the Fancybox integration.
'dev > php' 카테고리의 다른 글
PHP MySQLi Database Class (1) | 2015.02.16 |
---|---|
Mongodb :: createDBRef, getDBRef (0) | 2011.11.01 |
mail()함수를 이용하여 UTF-8 문서를 안전하게 보내는 방법 (0) | 2011.05.27 |
트위터 글쓰기 (0) | 2011.05.03 |
ARRAY to XML (2) | 2011.03.25 |