2017-05-10 45 views
1

私は私のTwitterのフォロワー数は私のウェブサイト上で表示するために取得しようとしています。フォロワー数を受け取るようtwitter APIを設定しました。これはechoを使ってテストされており、完全に動作しています。phpからpタグ(html)に変数を挿入するには?

問題は、私は、HTMLの中にその値を渡す方法を動作することはできませんです。

これはTwitterの回数取得するコードです:

<?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']; 

?> 

を、これはHTMLに$のfollowers_count変数を渡すためのコードです。

それは、ID「なじる・フォロー数」とspanタグです。

<script type="text/javascript"> 

$(document).ready(function() { 
    $('#twit-follow-count').html($followers_count); 
}); 

</script> 

ご協力いただければ幸いです。

答えて

3
<script type="text/javascript"> 

$(document).ready(function() { 
    $('#twit-follow-count').html('<?php echo $followers_count; ?>'); 
}); 

</script> 
+0

はい。それは私がやることです! – Sank6

+0

?私はそれを上回った。それが私ができることのすべてです。私はその質問をしなかった。 – Sank6

+0

申し訳ありませんが、ニックネームを見ませんでした。 – Mowshon

関連する問題