尝试通过TwitterOAuth检索主题标签返回“未定义”

时间:2019-01-07 19:30:00

标签: javascript php jquery api twitter

用于检索推文的代码段:

<?php
header('Content-type: application/json');

require "config.php"; //Containing consumer key and consumer secret
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);

$query = array(
"q" => "#CM0677",
"count" => 5,
"result_type" => "recent"
);

$tweets = $connection->get('search/tweets', $query);

echo(json_encode($tweets));
?>

通过JS附加到HTML的代码片段:

$(document).ready(function() {
    //get the JSON data that is echoed out in the //call_twitter_API.php code
    $.getJSON("call_twitter_API.php",function(tweetdata) {
        $.each(tweetdata, function(i, tweet){
            $("#tweet-list").append("<li>" + tweet.text +"</li>");
        });
    })
})

HTML文件包含ID为tweet-list的UL

0 个答案:

没有答案