Php 我如何解析Twitter api返回的json数据并在我的网页上使用它?

Php 我如何解析Twitter api返回的json数据并在我的网页上使用它?,php,html,json,twitter,Php,Html,Json,Twitter,首先,我使用的是上面提到的代码。我按照别人的建议做了一切,我为我的应用程序生成了密钥并将其放入代码中。当我运行它时,我看到了巨大的json字符串,基本上所有内容都在那里。这里有一部分向您展示了我得到的确切信息: 数组([0]=>stdClass对象([created_at]=>Thu May 14 20:06:37 +0000 2015[id]=>5989425114966784000[id_str]=>5989425114966784000[text]=>这是我的第一条推特#你好 [sourc

首先,我使用的是上面提到的代码。我按照别人的建议做了一切,我为我的应用程序生成了密钥并将其放入代码中。当我运行它时,我看到了巨大的json字符串,基本上所有内容都在那里。这里有一部分向您展示了我得到的确切信息:

数组([0]=>stdClass对象([created_at]=>Thu May 14 20:06:37 +0000 2015[id]=>5989425114966784000[id_str]=>5989425114966784000[text]=>这是我的第一条推特#你好 [source]=>Twitter Web客户端[被截断]=>[在对状态的回复中] =>[回复状态中的用户id=>[回复用户id中的用户id]=>[回复用户id中的用户id中的用户id=>[回复屏幕中的用户名称]=>[用户]=> stdClass对象([id]=>3064494912[id\u str]=>3064494912[name]=> HelloToUserName[屏幕名称]=>helloHQ[位置]=>[说明]=> [url]=>[entities]=>stdClass对象([description]=>stdClass 对象([URL]=>Array())[protected]=>[followers\u count]=>0 [friends\u count]=>0[列出的\u count]=>0[创建时间]=>2月27日星期五 17:39:51+0000 2015[收藏夹计数]=>0[utc偏移]=>7200 [时区]=>贝尔格莱德[地理位置启用]=>[验证]=> [状态统计]=>3[lang]=>en[已启用贡献者]=> [是否启用翻译]=>[是否启用翻译]=> [profile\u background\u color]=>C0Dect[profile\u background\u image\u url]=> [profile\u background\u image\u url\u https]=> [profile\u background\u tile]=>[profile\u image\u url]=> [profile\u image\u url\u https]=> [配置文件链接颜色]=>0084B4[配置文件侧栏颜色]=> c0dect[profile\u边栏\u fill\u color]=>DDEEF6[profile\u text\u color]=> 333333[配置文件\u使用\u背景\u图像]=>1[已扩展\u配置文件]=> [默认配置文件]=>1[默认配置文件图像]=>[以下]=> [跟踪请求发送]=>[通知]=>)[geo]=>[坐标] =>[place]=>[contributors]=>[is quote\u status]=>[retweet\u count]=>0[favorite\u count]=>0[entities]=>stdClass对象([hashtags]=>Array([0]=>stdClass对象([text]=>hello[Indexs]=>Array([0]=>35=>43))=>stdClass对象([text]=> hashtag[索引]=>Array([0]=>45=>53))[symbols]=> 数组()[user\u提到]=>Array()[url]=>Array()) [favorited]=>[retweeted]=>[lang]=>en=>stdClass对象( [创建时间]=>2015年5月12日星期二20:38:39+0000[id]=> 598225796945847936[id_str]=>598225796945847936[text]=>这是我的第二条推特"你好# [source]=>Twitter Web客户端[被截断]=>[在对状态的回复中] =>[答复用户身份信息时]=>[答复用户身份信息时]=>[答复用户身份信息时]=>[答复用户身份信息时]=>

等等

另一方面,我的网页上有一个twitter容器:

<section class="twitter-container">
            <div class="twitter">
                <ul class="tweet_list" id="tweet_list">
                    <li class="tweet_first tweet_even">
                        <span class="tweet_text">I want to put here the text from my latest tweets</span><span class="tweet_time"><a href="http://twitter.com/mytwitteraccount" title="view tweet on twitter">date of first tweet</a></span>
                    </li>
                    <li class="tweet_even">
                        <span class="tweet_text">Again, the same as above, how can I put here latest #tweet?
                            <a href="#">#myFirstTweet</a></span><span class="tweet_time"><a href="http://twitter.com/mytwitteraccount" title="view tweet on twitter">date of 2nd tweet</a></span>
                    </li>

                </ul>
            </div>
        </section>

  • 我想把我最近的推文放在这里
  • 同样,如上所述,我怎样才能把最新的推特放在这里?
现在-你能帮我解析json并在html代码中拟合结果吗?我想把最后5条推文和它们的日期和时间放在那里。非常感谢你可以使用这段代码($tweets变量是包含所有推文的数组):


    <section class="twitter-container">
        <div class="twitter">
            <ul class="tweet_list" id="tweet_list">
                <?php $t = 0; ?>
                <?php foreach ($tweets as $tweet) { ?>
                    <?php $t++; ?>
                    <?php if ($t>5) break; ?>
                    <li class="<?php if ($t==1) print 'tweet-first'; ?> tweet-<?php print $t; ?> tweet_even">
                        <span class="tweet_text"><?php print $tweet->text; ?></span><span class="tweet_time"><a href="http://twitter.com/mytwitteraccount" title="view tweet on twitter"><?php print $tweet->created_at; ?></a></span>
                    </li>
                <?php } ?>
            </ul>
        </div>
    </section>