Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Zend从statusesUserTimeline(twitter)访问响应?_Php_Arrays_Json_Twitter_Stdclass - Fatal编程技术网

Php 如何使用Zend从statusesUserTimeline(twitter)访问响应?

Php 如何使用Zend从statusesUserTimeline(twitter)访问响应?,php,arrays,json,twitter,stdclass,Php,Arrays,Json,Twitter,Stdclass,我是PHP新手,所以这可能是个愚蠢的问题,但我试图自己解决,但没有成功。 我正在尝试使用Zend Framework从Twitter获取一些信息,以下是回应: [jsonBody:protected] => Array ( [0] => stdClass Object ( [created_at] => Sat Jun 15 08:30:00 +0000 20

我是PHP新手,所以这可能是个愚蠢的问题,但我试图自己解决,但没有成功。 我正在尝试使用Zend Framework从Twitter获取一些信息,以下是回应:

    [jsonBody:protected] => Array
        (
            [0] => stdClass Object
                (
                    [created_at] => Sat Jun 15 08:30:00 +0000 2013
                    [id] => 3.4582047273635E+17
                    [id_str] => 345820472736354304
                    [text] => In Saturday Flashback, watch #FFC take a huge step towards     the Premier League with a vital win at Blackburn in 2001. http://t.co/iRWPDg7NmK
                    [source] => web
                    [truncated] => 
                    [in_reply_to_status_id] => 
                    [in_reply_to_status_id_str] => 
                    [in_reply_to_user_id] => 
                    [in_reply_to_user_id_str] => 
                    [in_reply_to_screen_name] => 
                    [user] => stdClass Object
                        (
                            [id] => 22903812
                            [id_str] => 22903812
                            [name] => Fulham Football Club
                            [screen_name] => FulhamFC
                            [location] => Fulham, London, England
                            [description] => The Official Twitter page of Fulham Football Club, London, England. http://t.co/GWMBbvhEfT #ffc #fulhamfc #coyw #bytheriver
                            [url] => http://t.co/qHWTVnXr2E
                            [entities] => stdClass Object
                                (
                                    [url] => stdClass Object
                                        (
                                            [urls] => Array
                                                (
                                                    [0] => stdClass Object
                                                        (
                                                            [url] => http://t.co/qHWTVnXr2E
                                                            [expanded_url] => http://www.fulhamfc.com
                                                            [display_url] => fulhamfc.com
                                                            [indices] => Array
                                                                (
                                                                    [0] => 0
                                                                    [1] => 22
                                                                )

                                                        )

                                                )

                                        )

                                    [description] => stdClass Object
                                        (
                                            [urls] => Array
                                                (
                                                    [0] => stdClass Object
                                                        (
                                                            [url] => http://t.co/GWMBbvhEfT
                                                            [expanded_url] => http://fulhamfc.com
                                                            [display_url] => fulhamfc.com
                                                            [indices] => Array
                                                                (
                                                                    [0] => 68
                                                                    [1] => 90
                                                                )

                                                        )

                                                )

                                        )

                                )

                            [protected] => 
                            [followers_count] => 139667
                            [friends_count] => 12662
                            [listed_count] => 2083
                            [created_at] => Thu Mar 05 10:10:44 +0000 2009
                            [favourites_count] => 16
                            [utc_offset] => 0
                            [time_zone] => London
                            [geo_enabled] => 
                            [verified] => 1
                            [statuses_count] => 11680
                            [lang] => en
                            [contributors_enabled] => 
                            [is_translator] => 
                            [profile_background_color] => 000000
                            [profile_background_image_url] => http://a0.twimg.com/profile_background_images/837307227/ac1a6a4096d1b8cda9276d169b57b889.jpeg
                            [profile_background_image_url_https] => https://si0.twimg.com/profile_background_images/837307227/ac1a6a4096d1b8cda9276d169b57b889.jpeg
                            [profile_background_tile] => 
                            [profile_image_url] => http://a0.twimg.com/profile_images/3178979663/5ef1b3abec0dec9e160491cb62c835f5_normal.jpeg
                            [profile_image_url_https] => https://si0.twimg.com/profile_images/3178979663/5ef1b3abec0dec9e160491cb62c835f5_normal.jpeg
                            [profile_banner_url] => https://pbs.twimg.com/profile_banners/22903812/1348050191
                            [profile_link_color] => 0084B4
                            [profile_sidebar_border_color] => FFFFFF
                            [profile_sidebar_fill_color] => DDEEF6
                            [profile_text_color] => 333333
                            [profile_use_background_image] => 1
                            [default_profile] => 
                            [default_profile_image] => 
                            [following] => 
                            [follow_request_sent] => 
                            [notifications] => 
                        )

                    [geo] => 
                    [coordinates] => 
                    [place] => 
                    [contributors] => 
                    [retweet_count] => 9
                    [favorite_count] => 5
                    [entities] => stdClass Object
                        (
                            [hashtags] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [text] => FFC
                                            [indices] => Array
                                                (
                                                    [0] => 29
                                                    [1] => 33
                                                )

                                        )

                                )

                            [symbols] => Array
                                (
                                )

                            [urls] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [url] => http://t.co/iRWPDg7NmK
                                            [expanded_url] => http://ow.ly/m3Ljl
                                            [display_url] => ow.ly/m3Ljl
                                            [indices] => Array
                                                (
                                                    [0] => 117
                                                    [1] => 139
                                                )

                                        )

                                )

                            [user_mentions] => Array
                                (
                                )

                        )

                    [favorited] => 
                    [retweeted] => 
                    [possibly_sensitive] => 
                    [lang] => en
                )

        )
我没有找到访问数据的方法,将对象强制转换到数组不起作用, 直接作为对象访问也不起作用。请告知

e、 g:


他们几天前改变了API。以下是如何做到这一点:

$accessToken = new Zend_Oauth_Token_Access();
$accessToken->setToken($config['twitter']['accessToken']);
$accessToken->setTokenSecret($config['twitter']['accessTokenSecret']);

$twitter = new Zend_Service_Twitter(
array(
                    'accessToken' => $accessToken,
                    'oauthOptions' => array(
                        'consumerKey' => $config['twitter']['consumerKey'],
                        'consumerSecret' => $config['twitter']['consumerSecret']
                    )
                )
            );

            $response = $twitter->statuses->statusesUserTimeline(array('count' => $config['twitter']['posts']));
            $response = $response->toValue();

。。。作为回应,您有一个带有POST的漂亮数组。

您无法访问类或其子对象之外的对象的受保护属性

要访问jsonBody和rawBody,必须在对象上相应地使用toValue()和getRawResponse()方法。方法在Zend/Service/Twitter/Response.php中定义

例如:

$response = $response->toValue();
echo $response[0]->text;
另一种方法是创建一个扩展Zend_Service_Twitter_Response的类,以便访问对象的所有受保护属性。这种方法只是为了说明继承是如何工作的

例如:

class Plugin_TwitterSearch extends Zend_Service_Twitter_Response
{
    public function __construct() {}
    public function search () {
        $twitter  = new Zend_Service_Twitter($options);  //$options - your consumer and access data
        $twits = $twitter->search->tweets('#zendframework', array('count' => 100));
        var_dump($twits->jsonBody);
        var_dump($twits->rawBody);
        exit;
   }
}
class Plugin_TwitterSearch extends Zend_Service_Twitter_Response
{
    public function __construct() {}
    public function search () {
        $twitter  = new Zend_Service_Twitter($options);  //$options - your consumer and access data
        $twits = $twitter->search->tweets('#zendframework', array('count' => 100));
        var_dump($twits->jsonBody);
        var_dump($twits->rawBody);
        exit;
   }
}