【问题标题】:Twitter API 1.1 does not giving correct timeTwitter API 1.1 没有给出正确的时间
【发布时间】:2014-01-05 00:51:34
【问题描述】:

我正在开发 Twitter API 1.1。我想从 twitter 获取推文以进行特定搜索。这是我的代码:-

<?php

  date_default_timezone_set('Asia/Calcutta');

  include "library/twitteroauth.php";

$consumerkey = "MY_CONSUMER _KEY";
$consumersecret = "CONSUMER_SECRET_KEY";
$accesstoken = "ACCESS_TOKEN";
$accesstokensecret = "ACCESS_TOKEN_SECRET";

$twitter = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

/* FOR PARTICULAR SEARCH */

$tweets = $twitter -> get('https://api.twitter.com/1.1/search/tweets.json?q='.$_POST['keyword']. '&img->tr&result_type=recent&count=50&until=2013-12-15'); //$_POST['keyword'] is a search text e.g. king

    foreach($tweets as $tweet){

       foreach($tweet as $t){

        $tweet_time = date("l M j \- g:ia",strtotime($t->created_at));

        echo 'Time----->'.date("l M j \- g:ia",strtotime($t->created_at));  


        echo '<pre>';
        print_r($t); 
?>

一切正常,所有推文都成功发送,但推文时间不正确。请看下面的截图:-

如何从 twitter 获取推文的实际时间。我的时区是亚洲/加尔各答 - 印度

【问题讨论】:

  • 我相信“created_at”字段是UTC。您的应用程序逻辑应该读取该数据并将其转换为在您当前的语言环境中显示。

标签: php twitter


【解决方案1】:

来自其余 API 的推文始终以创建推文时的 UTC 时间返回。 See the Twitter documentation for this here

您的应用程序需要读取该日期/时间并将其转换为您当前的时区。要在 PHP 中执行此操作,请查看 php 的内置函数,例如 datestrtotime,记住您需要根据自己的时区增加或减少一定的小时数。

【讨论】:

    猜你喜欢
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多