使用搜索字词加载推文而不是用户名

时间:2013-06-19 20:48:18

标签: php search twitter tweets

现在我使用这样的用户名从twitter加载推文:(密码和令牌填写在我的代码中)

<?php
session_start();
require_once("twitteroauth/twitteroauth.php"); // PATH TO TWITTEROUTH LIBRARY

if(isset($_GET['twitteruser']) && !empty($_GET['twitteruser'])) {
    $twitteruser = $_GET['twitteruser']; // USER
}
$notweets = 60; // NUMBER OF TWEETS

// OAUTH SETTINGS APPLICATION (https://dev.twitter.com/apps/)
$consumerkey = "";
$consumersecret = "";
$accesstoken = "";
$accesstokensecret = "";

function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
}

$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);

$data =  json_encode($tweets);

?>

正如您所看到的,我使用用户名加载推文并设置推文数量。
是否可以轻松更改以使用搜索字词加载推文?

我在google上搜索但奇怪的是我找不到多少。

我在twitter API中发现了这一点,但这似乎不起作用..

  

https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&since_id=24012619984051000&max_id=250126199840518145&result_type=mixed&count=4

来源:https://dev.twitter.com/docs/api/1.1/get/search/tweets
(我改变了链接到该链接)

但是我用var_dump得到了这个输出:

  

string(319)“{”status“:[],”search_metadata“:{”completed_in“:0.004,”max_id“:2.50126199841e + 17,”max_id_str“:”250126199840518145“,”查询“:”% 23freebandnames”, “refresh_url”: “since_id = 250126199840518145&安培; q =%23freebandnames&安培; result_type的=混合&安培; include_entities = 1”, “计数?”:4 “since_id”:2.40126199841e + 16 “since_id_str”: “24012619984051000”} }” .....

1 个答案:

答案 0 :(得分:1)

Twitter搜索API仅返回过去一周左右的推文。查看更多信息here

  

搜索API不是所有推文的完整索引,而是最近推文的索引。目前索引包含6-9天的推文。

请注意,Twitter网站上的搜索功能会查询历史推文,它只是不支持它们的API。

相关问题