简体   繁体   中英

How to get value of stdClass object returned from twitter API?

I am using twitter API to to get application rate limit. When I made a request I get the following response (using print_r );

stdClass Object
(
[rate_limit_context] => stdClass Object
    (
        [application] => Vu62t75UIKwKA392lipsQPB91
    )

[resources] => stdClass Object
    (
        [search] => stdClass Object
            (
                [/search/tweets] => stdClass Object
                    (
                        [limit] => 450
                        [remaining] => 450
                        [reset] => 1475485694
                    )

            )

    )

[httpstatus] => 200
[rate] => stdClass Object
    (
        [limit] => 180
        [remaining] => 176
        [reset] => 1475485014
    )

)

I am able to get values on every key as

$apiStatus= $limitJsonResponse->httpstatus;
$apiRateLimit=$limitJsonResponse->rate->limit;

But I am not able to find a way to access values of this property [/search/tweets] .

If I try get value of this property as other

$limit =$limitJsonResponse->resources->search->/search/tweets->remaining;

I get this error

Parse error: syntax error, unexpected '/', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'

I don't know if it is a good answer but it solved my problem I devided stdClass in object and expand trough the last one.

    $param=array('resources'=>'search');
    $limitJsonResponse=$apiObj->application_rateLimitStatus($param,true);

    // an stdClass object
    $searchObj=$limitJsonResponse->resources->search;

    $searchArray = (array)$searchObj;
    $searchTweetObj =$searchArray['/search/tweets'];
    $limit= $searchTweetObj->limit;
    echo $limit;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM