如何在网站上获得动态的Twitter时间表?

时间:2014-01-16 08:44:46

标签: twitter

我正试图在网上商店获得动态时间表。它必须显示有关产品的推文,所以我必须查询。但我找不到有关如何执行此操作的任何有用信息。我不想创建一个小部件,因为它不再是动态的。 我试过这个:https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&count=4 但这也不起作用。

有可能这样做吗?如果是,请帮助我,如果不是Twitter必须羞耻和工作:P

2 个答案:

答案 0 :(得分:3)

首先,您可以参考 https://github.com/J7mbo/twitter-api-php

从上述GitHub存储库下载并包含TwitterAPIExchange.php,或按照以下提及的步骤进行操作:

<?php

    include("TwitterAPIExchange.php");
    $query = "freebandnames"; 

    /** Set access tokens here - see: https://dev.twitter.com/apps/ **/
    $settings = array(
        'oauth_access_token' => "YOUR_OAUTH_ACCESS_TOKEN",
        'oauth_access_token_secret' => "YOUR_OAUTH_ACCESS_TOKEN_SECRET",
        'consumer_key' => "YOUR_CONSUMER_KEY",
        'consumer_secret' => "YOUR_CONSUMER_SECRET"
    );
    $url = "https://api.twitter.com/1.1/search/tweets.json";
    $requestMethod = "GET";
    $getfield = '?q='.$query.'&count=100';
    $twitter = new TwitterAPIExchange($settings);
    $result = json_decode($twitter->setGetfield($getfield)->buildOauth($url,  $requestMethod)->performRequest(),$assoc = TRUE);

?>

<强>输出

<pre>
    <?php echo $result;?>
</pre>

答案 1 :(得分:1)

Of course you can have dynamic twitter feeds using widgets and single data-widget-id,just copy and paste the following code

    <div>
<a class="twitter-timeline"  data-widget-id="659684039234682880"  data-screen-name="yourTwitterName" ></a></div>

    <script>!function (d, s, id) {
     var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https'; if (!d.getElementById(id)) { js = d.createElement(s); js.id = id; js.src = p + "://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); }
    }(document, "script", "twitter-wjs");

    </script>

for,

    data-screen-name="yourTwitterName"

to make it dynamic, you can query the twitter name from a local database when different users are logged in. Hope this helps..!