2013-05-10 35 views
0

我正在學習Instagram的API作爲一個副項目。我遵循本教程(http://eduvoyage.com/instagram-search-app.html)通過hashtag實現搜索功能。這對我非常有幫助。我在API中看到的一件事是位置ID功能,我想知道如何實現它。通過在本網站上搜索,我發現可以做出返回以下內容的請求。Instagram的地理標記API

'{ 
"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(如上面的教程鏈接),能夠點擊圖片結果,打開一個顯示圖片和用戶配置文件的選項卡,以及另一個顯示所有圖像元數據的選項卡。有沒有更簡單的方法來做到這一點?或者更小巧的友好教程?

回答

0

我在使用這個例子時遇到了類似的問題。您必須在此示例的頂部包含Zend框架的路徑。我只是在自己的php塊頂部。

ini_set('include_path', 'path/to/ZendFramework/library');