Twitter响应中的PHP未定义属性

时间:2015-03-24 20:26:55

标签: php

我在访问从Twitter api返回的stdClass中的一个属性时遇到问题,我正在尝试获取名为extended_entities的属性,但PHP不断返回错误,抱怨该属性不存在。我可以在var_dump中清楚地看到它。见输出:

object(stdClass)[597]
public 'created_at' => string 'Mon Mar 23 16:39:25 +0000 2015' (length=30)
public 'id' => int 580046201061580800
public 'id_str' => string '580046201061580800' (length=18)
...
public 'user' => 
object(stdClass)[600]

          ...
  ...
  public 'notifications' => boolean false
public 'geo' => null
...
public 'entities' => 
object(stdClass)[581]
  public 'hashtags' => 
    array (size=0)
      empty
  public 'symbols' => 
    array (size=0)
      empty
  public 'user_mentions' => 
    array (size=0)
      empty
  public 'urls' => 
    array (size=0)
      empty
  public 'media' => 
    array (size=1)
      0 => 
        object(stdClass)[593]
          ...
public 'extended_entities' => 
object(stdClass)[573]
  public 'media' => 
    array (size=2)
      0 => 
        object(stdClass)[556]
          ...
      1 => 
        object(stdClass)[595]
          ...
public 'favorited' => boolean false
public 'retweeted' => boolean false
public 'possibly_sensitive' => boolean false
public 'possibly_sensitive_appealable' => boolean false
public 'lang' => string 'en' (length=2)

以下列方式获取属性(例如转推,created_at等)没有问题:

$response->retweeted  //this returns false
$response->user //returns stdClass

然而

$response->extended_entities

$response->extended_entities->media 

返回

  

注意:未定义的属性:stdClass :: $ extended_entities

我希望分别拥有对象或数组。我不明白为什么我可以访问某些属性而不是这个?

0 个答案:

没有答案