I was working with Google Oauth 2 and finally was able to get the access token. Google simply returned the access token in a JSON object. The output was printed out on my browser. Since I've never touched JSON or any other API before, I have no idea how to capture that JSON object so I can store the access token.
Example Output(obscured the actual data)
{
"access_token":"1/6GKFqrOr6000000004k10qgr000000GiUiRNbLnc",
"token_type":"Bearer",
"expires_in":3600,
"refresh_token": "1/Vx34LfPISDuX000000Kq_SJWIgf42FVs"
}
I tried the simple $token = $_POST['access_token']; which didn't work. json_decode also didn't work. I'm pretty sure I'm not doing it right here. Can someone tell me how you can interact with JSON object?
EDIT:
I guess my initial question is more rudimentary because I'm really new at API programming. What I want to know is how to encapsulate the browser response of a JSON object into a variable so my PHP script can dynamically decode the response. Currently, the browser just replied the content of the JSON object like I posted above but I don't know the object name or variable name like $object = {}. Is there any way to find out the object name or a way to put the response into an object or array dynamically?