V
V
Vitaly2017-04-24 15:28:19
PHP
Vitaly, 2017-04-24 15:28:19

How to get a parameter with a variable value from JSON using PHP?

VK has a way to get a community key Authorization Code Flow , I get a temporary access code (no problem), I get a community token using this code. The JSON type is {"access_token_XXXXXX":"токен", "expires_in":0}
where XXXXXX is the community ID for which we are getting the token.
and as soon as it comes to displaying this token on the screen, the question arises, how will I display it ?? After all, the parameter where the token is located can have different XXXXXX values ​​​​depending on the community for which it was received, and display it using the command

$group_token = $request_token->response[0]->access_token;
will no longer come out because of this notorious XXXXXX in the access_token_XXXXXX parameter. How to do it?? Or is it impossible??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy Odinets, 2017-04-24
@vitcorp

you also have the id of the community for which you are requesting a token.

$group_id = '( . )( . )';
$array_key = 'access_token_' . $group_id;
$group_token = $request_token->response[0][$array_key];

In order to get an array instead of an object, you need to pass true as the second parameter to the json_decode function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question