0

I am a bit new to json. I get this below response from facebook oauth. And i am unable to get a proper way to get the data into variable/object in php.

{
   "data":{"app_id":xxxxxxxxxx,
           "is_valid":true,
           "application":"Opensource Education Dot in",
           "user_id":xxxxxxxxxx,
           "issued_at":1389448259,
           "expires_at":1394632259,
           "scopes":["basic_info","email","public_profile","user_friends"]
          }

}  

This where i am stuck. Dont know how to get each response. Also I only get this as response. But the exact values in the scope(like email, basic_info etc.) how do i get them?

$userdata=json_decode($response);
codename_subho
  • 456
  • 8
  • 22

1 Answers1

0

Use

$userdata=json_decode($response,true);

For the long userids issue you can use the below -

$userdata= = json_decode(preg_replace('/"uid":(\d+)/', '"uid":"$1"', $response),true);

Also Could be used as

$userdata=  json_decode($response, true, 512, JSON_BIGINT_AS_STRING)

It will give you an array.

In addition you can check the thread for more variations

How to get around or make PHP json_decode not alter my very large integer values?

Community
  • 1
  • 1
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
  • HI, the app id and userid are too long so getting it in exponential form. How do i solve this? – codename_subho Jan 11 '14 at 16:10
  • I have updated the answer check now.. you can replace the uid in the preg_replace with yours, I think its user_id in your case. – Abhik Chakraborty Jan 11 '14 at 16:18
  • You can check here for similar long userid issue answered by me before http://stackoverflow.com/questions/20931751/fql-api-issues-with-array-translation/20931887#20931887 – Abhik Chakraborty Jan 11 '14 at 16:19
  • I have two data that are long. app_id and user_id. So user_id is working fine. But 4 parameters were not accepted in the above format. So what about app_id – codename_subho Jan 11 '14 at 16:27
  • Then use json_decode($response, true, 512, JSON_BIGINT_AS_STRING); this will covert all the big ints to string. Let me update the answer. – Abhik Chakraborty Jan 11 '14 at 16:29