簡體   English   中英

我如何從新的twitter api 1.1獲得推文?

[英]How can I get tweets from new twitter api 1.1?

我剛剛為Laravel 4實現了https://github.com/thujohn/twitter-l4 ,它基本上從搜索標簽中提取了一系列推文。

看起來它的工作,我認為有些東西不起作用。

我得到一個沒有錯誤的空白屏幕,這意味着一個積極的跡象。

這是我的代碼。

PHP:

$tweets = Twitter::getSearch(array('q' => 'secretsocial', 'count' => 100, 'format' => 'array'));
var_dump($tweets);

這段代碼基本上給了我一個json數組:

array (size=2)
  'statuses' => 
    array (size=20)
      0 => 
        array (size=24)
          'metadata' => 
            array (size=2)
              'result_type' => string 'recent' (length=6)
              'iso_language_code' => string 'en' (length=2)
          'created_at' => string 'Fri May 16 14:28:14 +0000 2014' (length=30)
          'id' => int 467310562603331586
          'id_str' => string '467310562603331586' (length=18)
          'text' => string 'On that #merch #grind. #spotify #swag just got shipped in. #secretsocial #free #leeds #leedsuni… http://t.co/67phqjeg5W' (length=121)
          'source' => string '<a href="http://instagram.com" rel="nofollow">Instagram</a>' (length=59)
          'truncated' => boolean false
          'in_reply_to_status_id' => null
          'in_reply_to_status_id_str' => null
          'in_reply_to_user_id' => null
          'in_reply_to_user_id_str' => null
          'in_reply_to_screen_name' => null
          'user' => 
            array (size=40)
              'id' => int 167993141
              'id_str' => string '167993141' (length=9)
              'name' => string 'Maral Erol' (length=10)
              'screen_name' => string 'liaaca' (length=6)
              'location' => string 'Leeds / San Diego' (length=17)
              'description' => string 'Music/Culture/Entertainment Enthusiast.' (length=39)
              'url' => string 'http://t.co/FL3uuA6QcN' (length=22)
              'entities' => 
                array (size=2)
                  'url' => 
                    array (size=1)
                      'urls' => 
                        array (size=1)
                          0 => 
                            array (size=4)
                              'url' => string 'http://t.co/FL3uuA6QcN' (length=22)
                              'expanded_url' => string 'http://linkd.in/R70tjB' (length=22)
                              'display_url' => string 'linkd.in/R70tjB' (length=15)
                              'indices' => 
                                array (size=2)
                                  0 => int 0
                                  1 => int 22
                  'description' => 
                    array (size=1)
                      'urls' => 
                        array (size=0)
                          empty

所以我寫了這個:

if(isset($tweets->statuses) && is_array($tweets->statuses)) {
        if(count($tweets->statuses)) {
            foreach($tweets->statuses as $tweet) {
                echo $tweet->text;
            }
        }
        else {
            echo 'The result is empty';
        }
    }

我在頁面上沒有錯誤。 有人能指出我正確的方向嗎?

干杯

由於每個$tweet都是一個數組,所以你應該使用$tweet['text']而不是$tweet->text

foreach($tweets->statuses as $tweet) {
    echo $tweet['text'];
}

另外$tweets->statuses應該是$tweets['statuses'] $tweets->statuses $tweets['statuses']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM