【问题标题】:using twitter API to search tweets使用 twitter API 搜索推文
【发布时间】:2014-04-21 22:12:36
【问题描述】:

我正在尝试使用 twitter API 根据位置搜索推文 本质上我想使用链接 1.1/search/tweets.json?q=...... IT 进展顺利,说明解析或分解结果的要点 我无法阅读推文...不知道为什么

我使用不同的方法取得了成功 这是我的代码

<?php
require 'tmhOAuth.php'; // Get it from: https://github.com/themattharris/tmhOAuth

 // Use the data from http://dev.twitter.com/apps to fill out this info
 // notice the slight name difference in the last two items)
 $file = fopen("data.txt","w");
 $connection = new tmhOAuth(array(
 'consumer_key' => 'key',
'consumer_secret' => 'key',
'user_token' => 'key', //access token
'user_secret' => 'key' //access token secret
    ));
   if ($_GET['twitter_path']) { $twitter_path = $_GET['twitter_path']; }  else {
$twitter_path = '1.1/statuses/user_timeline';
   }

    $http_code = $connection->request('GET', $connection->url($twitter_path), array ('screen_name' =>'latimesquakes'));
    if ($http_code === 200) { // if everything's good
$response = strip_tags($connection->response['response']);
$twitFeed = json_decode($response, true);
if ($_GET['callback']) { // if we ask for a jsonp callback function
    echo $_GET['callback'],'(', $response,');';
} else {
foreach ($twitFeed as $tweet)
{

    echo fwrite($file,$tweet['text']."\n");
   echo $tweet['text'].'<br>';
   }
  }
}
  else {
echo "Error ID: ",$http_code, "<br>\n";
echo "Error: ",$connection->response['error'], "<br>\n";
 }

但此代码不允许我根据位置进行搜索 所以任何人都可以建议如何使用此代码根据位置进行搜索 或建议使用 1.1/search/tweets.json 的代码?根据位置搜索 我的项目基于获取有关洛杉矶地震的推文 提前致谢

【问题讨论】:

  • 不要包含你该死的 API 密钥!
  • 如果您还没有撤销密钥,请撤销。删除修订只能做这么多。

标签: php json twitter


【解决方案1】:

我建议你为它使用一个库,例如https://github.com/dg/twitter-php。 (我用过一次,效果很好)

【讨论】:

  • 所以我只需要将这个文件包含到我的代码中。并且 json_decode 将起作用....??所以 foreach 会接受它
  • @user3385409 抱歉,它是付费项目,并且仅在私有存储库中:(
猜你喜欢
  • 2013-08-19
  • 1970-01-01
  • 2012-09-26
  • 2015-12-10
  • 1970-01-01
  • 1970-01-01
  • 2013-05-30
  • 2018-09-15
  • 1970-01-01
相关资源
最近更新 更多