doupo5178 2013-06-19 20:48
浏览 51
已采纳

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

Now I load the tweets from twitter by using a username like this: (keys and tokens are filled in my code)

<?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);

?>

As you can see I load the tweets with a username and set the number of tweets.
Can this easily be changed to load tweets with a search term?

I've search on google but strangely I can't find much.

I've found this in the twitter API but that doesn't seem to work ..

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

source: https://dev.twitter.com/docs/api/1.1/get/search/tweets
(I changed the link to that link)

But I get this output with a var_dump:

string(319) "{"statuses":[],"search_metadata":{"completed_in":0.004,"max_id":2.50126199841e+17,"max_id_str":"250126199840518145","query":"%23freebandnames","refresh_url":"?since_id=250126199840518145&q=%23freebandnames&result_type=mixed&include_entities=1","count":4,"since_id":2.40126199841e+16,"since_id_str":"24012619984051000"}}".....

  • 写回答

1条回答 默认 最新

  • drau67562 2013-06-19 21:11
    关注

    The Twitter search API only returns tweets from the past week or so. See more info here.

    The Search API is not complete index of all Tweets, but instead an index of recent Tweets. At the moment that index includes between 6-9 days of Tweets.

    Note that the search feature on Twitter's website does query historical tweets, it is just the API that does not support them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效