abraham / twitteroauth

The most popular PHP library for use with the Twitter OAuth REST API.
https://twitteroauth.com
MIT License
4.3k stars 1.71k forks source link

No stdClass::$next_results in public $search_metadata #849

Closed whitesiroi closed 4 years ago

whitesiroi commented 4 years ago

I tested it with: $ twurl /1.1/search/tweets.json?q=#AFA2019&since_id=1182587607596687360&result_type=mixed&count=10

{
   "statuses":[
   .......
   ],
   "search_metadata":{
      "completed_in":0.03,
      "max_id":1270569162448859137,
      "max_id_str":"1270569162448859137",
      "next_results":"?max_id=1270569162448859136&q=%23AFA2019&include_entities=1",
      "query":"%23AFA2019",
      "refresh_url":"?since_id=1270569162448859137&q=%23AFA2019&include_entities=1",
      "count":15,
      "since_id":0,
      "since_id_str":"0"
   }
}

But when I run it with php code:

    $tweetResult = $connection->get(
        "search/tweets",
        [
            'q'           => "#AFA2019",
            'result_type' => 'mixed',
            'max_id'      => '1182587607596687360',
            'count'       => 10,
        ]
    );
    var_dump($tweetResult); die();

I'm getting everything except "next_results"

 class stdClass#4 (2) {
   public $statuses =>
   array(0) {
   }
   public $search_metadata =>
   class stdClass#9 (8) {
     public $completed_in =>
     double(0.003)
     public $max_id =>
     int(1182587607596687360)
     public $max_id_str =>
     string(19) "1182587607596687360"
     public $query =>
     string(10) "%23AFA2019"
     public $refresh_url =>
     string(79) "?since_id=1182587607596687360&q=%23AFA2019&result_type=mixed&include_entities=1"
     public $count =>
     int(10)
     public $since_id =>
     int(0)
     public $since_id_str =>
     string(1) "0"
   }
 }

I'm using:

PHP 7.2.6-dev (cli) (built: May 11 2018 12:52:08) ( NTS )
"abraham/twitteroauth": "^1.1.0"
abraham commented 4 years ago

Your twurl version is using since_id and your PHP version is using max_id. If you switch the max_id to since_id the PHP version has next_results.

> twurl "/1.1/search/tweets.json?q=#AFA2019&since_id=1182587607596687360&result_type=mixed&count=10" | jq '.search_metadata'
{
  "completed_in": 0.031,
  "max_id": 1273601471582331000,
  "max_id_str": "1273601471582330880",
  "next_results": "?max_id=1271731611097354239&q=%23AFA2019&count=10&include_entities=1&result_type=mixed",
  "query": "%23AFA2019",
  "refresh_url": "?since_id=1273601471582330880&q=%23AFA2019&result_type=mixed&include_entities=1",
  "count": 10,
  "since_id": 1182587607596687400,
  "since_id_str": "1182587607596687360"
}
$connection = new TwitterOAuth(
    CONSUMER_KEY,
    CONSUMER_SECRET,
    ACCESS_TOKEN,
    ACCESS_TOKEN_SECRET
);
$tweetResult = $connection->get(
  "search/tweets",
  [
      'q'           => '#AFA2019',
      'since_id'    => '1182587607596687360',
      'result_type' => 'mixed',
      'count'       => 10,
  ]
);
var_dump($tweetResult->search_metadata);
> php sample.php 
object(stdClass)#42 (9) {
  ["completed_in"]=>
  float(0.059)
  ["max_id"]=>
  int(1273601471582330880)
  ["max_id_str"]=>
  string(19) "1273601471582330880"
  ["next_results"]=>
  string(86) "?max_id=1271731611097354239&q=%23AFA2019&count=10&include_entities=1&result_type=mixed"
  ["query"]=>
  string(10) "%23AFA2019"
  ["refresh_url"]=>
  string(79) "?since_id=1273601471582330880&q=%23AFA2019&result_type=mixed&include_entities=1"
  ["count"]=>
  int(10)
  ["since_id"]=>
  int(1182587607596687360)
  ["since_id_str"]=>
  string(19) "1182587607596687360"
}
whitesiroi commented 4 years ago

@abraham thank you very much for your help

Is there a way to use max_id in the php version and still get the next_results like with twurl ?

$ twurl /1.1/search/tweets.json?q=#高一ミスコン&max_id=1153128225284866050&result_type=mixed&count=2

  "search_metadata": {
    "completed_in": 0.074,
    "max_id": 1274798554079322000,
    "max_id_str": "1274798554079322112",
    "next_results": "?max_id=1273177711868030977&q=%23%E9%AB%98%E4%B8%80%E3%83%9F%E3%82%B9%E3%82%B3%E3%83%B3&include_entities=1",
    "query": "%23%E9%AB%98%E4%B8%80%E3%83%9F%E3%82%B9%E3%82%B3%E3%83%B3",
    "refresh_url": "?since_id=1274798554079322112&q=%23%E9%AB%98%E4%B8%80%E3%83%9F%E3%82%B9%E3%82%B3%E3%83%B3&include_entities=1",
    "count": 15,
    "since_id": 0,
    "since_id_str": "0"
  }

Php code:

$tweetResult = $connection->get(
    "search/tweets",
    [
        'q'           => "#高一ミスコン",
        'result_type' => 'mixed',
        'max_id'      => 1153128225284866050,
        'count'       => 2,
    ]
);
var_dump($tweetResult); die();

Result:

 class stdClass#4 (2) {
   public $statuses =>
   array(0) {
   }
   public $search_metadata =>
   class stdClass#9 (8) {
     public $completed_in =>
     double(0.003)
     public $max_id =>
     int(1153128225284866050)
     public $max_id_str =>
     string(19) "1153128225284866050"
     public $query =>
     string(57) "%23%E9%AB%98%E4%B8%80%E3%83%9F%E3%82%B9%E3%82%B3%E3%83%B3"
     public $refresh_url =>
     string(126) "?since_id=1153128225284866050&q=%23%E9%AB%98%E4%B8%80%E3%83%9F%E3%82%B9%E3%82%B3%E3%83%B3&result_type=mixed&include_entities=1"
     public $count =>
     int(2)
     public $since_id =>
     int(0)
     public $since_id_str =>
     string(1) "0"
   }
 }