【发布时间】:2017-10-09 10:02:46
【问题描述】:
我正在尝试让我的 twitter 关注者数量显示在我的网站上。我已经设置了 twitter API 来接收关注者数量,并且已经使用 echo 进行了测试,并且运行良好。
问题是我不知道如何将该值传递给 html。
这是获取推特计数的代码:
<?php
/*
* Requires the "Twitter API" wrapper by James Mallison
* to be found at https://github.com/J7mbo/twitter-api-php
*
* The way how to get a follower count was posted by Amal Murali
* on http://stackoverflow.com/questions/17409227/follower-count-number-in-twitter
*/
require_once('twitterapi/TwitterAPIExchange.php'); // adjust server path accordingly
// GET YOUR TOKENS AND KEYS at https://dev.twitter.com/apps/
$settings = array(
'oauth_access_token' => "SECRET", // enter your data here
'oauth_access_token_secret' => "SECRET", // enter your data here
'consumer_key' => "SECRET", // enter your data here
'consumer_secret' => "SECRET" // enter your data here
);
$ta_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=SECRET'; // enter your twitter name without the "@" here
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$follow_count=$twitter->setGetfield($getfield)
->buildOauth($ta_url, $requestMethod)
->performRequest();
$data = json_decode($follow_count, true);
$followers_count = $data[0]['user']['followers_count'];
?>
这是将 $followers_count 变量传递到 html 的代码。
这是一个 ID 为“twit-follow-count”的跨度标签。
<script type="text/javascript">
$( document ).ready(function() {
$('#twit-follow-count').html($followers_count);
});
</script>
任何帮助将不胜感激!
【问题讨论】:
标签: javascript php jquery html twitter