dounanyin3179 2014-03-29 22:16
浏览 83
已采纳

消息:尝试获取非对象Codeigniter的属性

I'm trying to create a simple piece of PHP code to display tweets using the twitter API, that just displays tweets about EVE Online - as a test. The code below does work however, I get the following error PHP notice after it:

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: pages/about.php

Line Number: 17

Here is my code:

<?php include('twitteroauth.php');?>
<?php include('get_tweet.php');?>
<div id="tweets">
<?php
    $tweets = $twitter->get('https://api.twitter.com/1.1/search/tweets.jsonq=EveOnline&
    result_type=recent&count=10'    );
foreach($tweets as $tweet)
{
    foreach($tweet as $t)
    {
    echo '<div id="tweetwrap"><img src="'.$t->user->profile_image_url.'"/>'
        .$t->text.'</div>';
    }
}
?>
</div>

I'm not using CodeIgniter's controllers or methods to do this. I'm trying to do it outside of CodeIgniter whilst using CodeIgniter for everything else. I'm sure there's a way, however I don't understand why CodeIgniter displays errors when I'm not using any of it's controllers or methods.

I've also tried this:

    echo '<div id="tweetwrap"><img src="'.$t->user['profile_image_url'].'"/>'
        .$t['text'].'</div>';

But this also does not work. Please help.

  • 写回答

2条回答 默认 最新

  • dtd14883 2014-03-30 14:09
    关注

    got it, basically i replaced the foreach loop with this:

    <?php include('twitteroauth.php');?>
    <?php include('get_tweet.php');?>
    <div id="tweets">
    <?php
    foreach($tweets->statuses as $status)
    {
        echo '<div id="tweetwrap"><img src="'.$status->user-
    >profile_image_url.'"/>';
        echo "User: " .$status->user->screen_name."</br>";
        echo "<p>Tweet: " .$status->text."</p></br>";
        echo "</br></div>";
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料