Instagram API和Zend / Loader.php

时间:2014-08-21 16:00:46

标签: api zend-framework instagram

我想使用Instagram API,我找到了这段代码。

<html>
  <head></head>
  <body>  
    <h1>Popular on Instagram</h1>  
    <?php
    // load Zend classes
    require_once 'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Http_Client');

    // define consumer key and secret
    // available from Instagram API console
    $CLIENT_ID = 'YOUR-CLIENT-ID';
    $CLIENT_SECRET = 'YOUR-CLIENT-SECRET';

    try {
      // initialize client
      $client = new Zend_Http_Client('https://api.instagram.com/v1/media/popular');
      $client->setParameterGet('client_id', $CLIENT_ID);

      // get popular images
      // transmit request and decode response
      $response = $client->request();
      $result = json_decode($response->getBody());

      // display images
      $data = $result->data;  
      if (count($data) > 0) {
        echo '<ul>';
        foreach ($data as $item) {
          echo '<li style="display: inline-block; padding: 25px"><a href="' . 
            $item->link . '"><img src="' . $item->images->thumbnail->url . 
            '" /></a> <br/>';
          echo 'By: <em>' . $item->user->username . '</em> <br/>';
          echo 'Date: ' . date ('d M Y h:i:s', $item->created_time) . '<br/>';
          echo $item->comments->count . ' comment(s). ' . $item->likes->count . 
            ' likes. </li>';
        }
        echo '</ul>';
      }

    } catch (Exception $e) {
      echo 'ERROR: ' . $e->getMessage() . print_r($client);
      exit;
    }
    ?>
  </body>
</html>

在这里,我找到了Zender / Load.php,我从来没有听说过。可以去http://www.zend.com/en/products/guard/downloads这里,下载Zend for linux吗? 而对于另一个问题,这个代码是否可以使用Instagram API? 最后,您能告诉我有没有使用Instagram API的简单代码?谢谢。

0 个答案:

没有答案