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条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?