2013-05-19 49 views
1

我試圖獲得在Twitter上搜索術語並迄今沒有運氣的用戶列表。這裏是我的代碼:Twitter OAuth - 從數組中獲取值

$parameters = array('q' => '#puppy', 'count' => 2); 
$results = $connection->get('search/tweets', $parameters); 

//print_r($result); 

foreach ($results as $data) { 

?> 

     <div id="update"> 
      <div id="left"><a href="https://twitter.com/#!/<?php echo $data->user->screen_name; ?>" target="_blank"/><img width="48px" height="48px" src="<?php echo $data->user->profile_image_url; ?>"/></a></div> 
      <div id="right"> 
       <div class="user"><a href="https://twitter.com/#!/<?php echo $data->user->screen_name; ?>" target="_blank"/><?php echo $data->user->screen_name; ?></a>&nbsp;<?php echo $data->user->name; ?></div> 
       <div class="detail"> 
       <?php echo $data->text; ?> 
       </div> 
      </div> 
     </div> 
<?php 
} 

,這就是它輸出:

Notice: Undefined property: stdClass::$user in line 150 
Trying to get property of non-object in line 150 

我知道我在訪問數組中的一個奇怪的方式,我只是無法弄清楚它是如何必須。

回答

1

對於那些可能需要這個的人來說,這只是一個以正確的方式從數組中獲取正確數據的問題。這裏是我使用的代碼:

 $parameters = array('q' => '#puppy', 'count' => 2); 
     $results = $connection->get('search/tweets', $parameters); 

     $resultsuser = $results->statuses[0]->user; 

     $i = 0; 
     foreach ($results->statuses as $data) { 

      $user_screen_name = $data->user->screen_name; 
      $user_profile_image_url = $data->user->profile_image_url; 
      $user_text = $data->text; 

     ?> 

       <div id="update"> 
        <div id="left"><a href="https://twitter.com/#!/<?php echo $user_screen_name; ?>" target="_blank"/><img width="48px" height="48px" src="<?php echo $user_profile_image_url; ?>"/></a></div> 
        <div id="right"> 
         <div class="user"><a href="https://twitter.com/#!/<?php echo $user_screen_name; ?>" target="_blank"/><?php echo $user_screen_name; ?></a>&nbsp;<?php echo $user_screen_name; ?></div> 
         <div class="detail"> 
         <?php echo $user_text; ?> 

         <hr/> 
         </div> 
        </div> 
       </div> 
     <?php 
     $i++; 
     } 


     ?> 
+0

謝謝!有用! – Branislav