简体   繁体   English

使用Twitter API 1.1将PHP转换为HTML

[英]PHP to html with twitter api 1.1

This is a simple question but i have the following php file that references some code to get a twitter follower count. 这是一个简单的问题,但是我有以下php文件,该文件引用了一些代码来获取Twitter追踪者计数。 This all works but in my html website file i want to display the "follower count" as text and in my php I am not sure what line to add. 所有这些都可以,但是在我的html网站文件中,我想以文本形式显示“跟随者计数”,而在我的php中,我不确定要添加哪一行。 I already have the script referenced in my html and right now i am trying to get it by using <span id="followers_count"></span> but nothing appears. 我已经在html中引用了该脚本,现在我正在尝试使用<span id="followers_count"></span>来获取它,但是什么也没有出现。 Am i doing that wrong or what do i add to my php file to take follower count and display it as text in my html? 我是做错了还是我要添加到我的php文件中以进行关注者计数并将其显示为html中的文本? Thanks! 谢谢!

<?php   
    require_once('js/twitter-api-php/TwitterAPIExchange.php');

    /** Set access tokens here - see: https://dev.twitter.com/apps/ **/
    $settings = array(
    'oauth_access_token' => "key here",
    'oauth_access_token_secret' => "key here",
    'consumer_key' => "key here",
    'consumer_secret' => "key here"
    );

    $ta_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
    $getfield = '?screen_name=inovize;
    $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'];
    echo $followers_count;

    *Do I add anything here to take followers_count to html text?*


    });

You are currently echoing out the count where ever this code resides in your PHP code, which is most likely at the top of your page. 当前,您正在回显此代码在PHP代码中的驻留位置,这很可能在页面顶部。

echo $followers_count;

comment out this line 注释掉这一行

//echo $followers_count;

and where you have your span echo that line 而你的跨度在那条线上回声

<span id="followers_count"><?php echo $followers_count; ?></span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM