2014-04-16 30 views
-1

當我試圖讓最近五年的鳴叫與小窗口,PHP返回此錯誤:與Twitter API致命錯誤不能使用類型爲stdClass的對象作爲數組

[Wed Apr 16 12:22:19.839947 2014] [:error] [pid 1987] [client 127.0.0.1:XXXX] PHP Fatal error: Cannot use object of type stdClass as array in /home/user/websites/html/dev_twitterwidget/index.php on line 31 

和線路31有這樣的代碼:

<a href="http://twitter.com/'.$tweet['from_user'].'" target="_blank"> 

而且所有的代碼來獲得鳴叫:

# Create the connection 
$twitter = new TwitterOAuth(CONSUMERKEY, CONSUMERSECRET, ACCESSTOKEN, ACCESSTOKENSECRET); 

# Migrate over to SSL/TLS 
$twitter->ssl_verifypeer = true; 

# Load the Tweets 
$tweets = $twitter->get('statuses/user_timeline', array('screen_name' => TWITTERUSERNAME, 'exclude_replies' => 'true', 'include_rts' => 'false', 'count' => TWEETLIMIT)); 

# Put this after fetching Tweets 
$twitter = ''; 

# Create the HTML output 
if(!empty($tweets)) { 
    foreach($tweets as $tweet) { 
     $twitter .= '<article> 
      <aside class="avatar"> 
       <a href="http://twitter.com/'.$tweet['from_user'].'" target="_blank"> 
        <img alt="'.$tweet['from_user'].'" src="'.$tweet['user']['profile_image_url'].'" /> 
       </a> 
      </aside> 
      <p>'.$tweet['created_at'].'</p> 
      <p>'.$tweet['text'].'</p> 
     </article>'; 
    } 
+2

投它應該是'$ tweet-> from_user' – hek2mgl

+0

哪個庫您使用? –

回答

0

,如果你想使用$tweetsarray而不是object這樣做。

$tweets = json_decode(json_encode($tweets), true); 

,或者你可以嘗試用(array)

+0

得到此錯誤:「PHP通知:未定義變量:推文」,問題依然存在:/ – MRROMAN

相關問題