0

我正在将 Instagram 的 API 作为一个副项目来学习。我已经按照本教程(http://eduvoyage.com/instagram-search-app.html)通过标签实现了搜索功能。这对我非常有帮助。我在 API 中看到的其中一件事是位置 ID 功能,我想知道如何实现它。通过在该站点上的搜索,我发现可以发出一个请求,该请求将返回以下内容。

'{
"meta":  {
"code": 200
},
"data":  {
"attribution": null,
"tags":  [],
"type": "image",
"location":  {
  "latitude": 48.8635,
  "longitude": 2.301333333
},
"comments":  {
  "count": 0,
  "data":  []
},
..........'

我正在尝试找出本教程来处理该信息。(http://www.ibm.com/developerworks/xml/library/x-instagram1/index.html#retrievedetails

<html>
<head>
<style>
</head>
<body>  
<h1>Instagram Image Detail</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 {
  // define image id
  $image = '338314508721867526';

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

  // get image metadata
  $response = $client->request();
  $result = json_decode($response->getBody());

  // display image data
 ?>
  <div id="container">
    <div id="info">
      <h2>Meta</h2>  
      <strong>Date: </strong> 
      <?php echo date('d M Y h:i:s', $result->data->created_time); ?>
      <br/>
      <strong>Creator: </strong>
      <?php echo $result->data->user->username; ?>
      (<?php echo !empty($result->data->user->full_name) ? 
        $result->data->user->full_name : 'Not specified'; ?>)
      <br/>
      <strong>Location: </strong>
      <?php echo !is_null($result->data->location) ?
      $result->data->location->latitude . ',' . 
        $result->data->location->longitude : 'Not specified'; ?>
      <br/>
      <strong>Filter: </strong>
      <?php echo $result->data->filter; ?>
      <br/>
      <strong>Comments: </strong>
      <?php echo $result->data->comments->count; ?>
      <br/>
      <strong>Likes: </strong>
      <?php echo $result->data->likes->count; ?>
      <br/>
      <strong>Resolution: </strong>
      <a href="<?php echo $result->data->images
        ->standard_resolution->url; ?>">Standard</a> | 
      <a href="<?php echo $result->data->images
        ->thumbnail->url; ?>">Thumbnail</a>
      <br/>
      <strong>Tags: </strong>
      <?php echo implode(',', $result->data->tags); ?>
      <br/>
    </div>
    <div id="image">
      <h2>Image</h2>  
      <img src="<?php echo $result->data->images
        ->low_resolution->url; ?>" /></a>
    </div>
    <div id="comments">
      <?php if ($result->data->comments->count > 0): ?>
      <h2>Comments</h2>
      <ul>
        <?php foreach ($result->data->comments->data as $c): ?>
          <div class="item"><img src="<?php echo $c
            ->from->profile_picture; ?>" class="profile" />
          <?php echo $c->text; ?> <br/>
          By <em> <?php echo $c->from->username; ?></em> 
          on <?php echo date('d M Y h:i:s', $c->created_time); ?>
          </div>

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

我遇到的主要问题(我认为)在这里: require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Http_Client');

我下载了 Zend Frame 1.12.13,但我不确定这行代码要求什么。在 Zend Framework 文件夹中,它是“Zend/Loader(Folder)”,但没有名为“Loader.php”。这只是加载'Loader'文件夹中的所有内容吗?Zend_Loader 也一样,有一个 Zend/Http/Client 的目录,但 Client 也是一个文件夹。

tl;dr 尝试设置一个搜索 instagram 的程序(如上面教程中的链接),能够单击图片结果,打开一个显示图片和用户个人资料的选项卡,以及另一个显示所有图像元数据。有没有更简单的方法来做到这一点?还是更菜鸟友好的教程?

4

1 回答 1

0

我在使用这个例子时遇到了类似的问题。您必须在此示例的最顶部包含 Zend 框架的路径。我只是在顶部自己的 php 块中完成了它。

ini_set('include_path', 'path/to/ZendFramework/library');
于 2014-07-08T03:15:16.450 回答