|
![Picture of Leandro Siow Picture of Leandro Siow](/graphics/unknown.gif) Leandro Siow - 2016-12-17 23:01:12
Sorry this might have been discussed, i read the documentation but not sure how to use the parameters to get callAPI function to return JSON instead of Associative Array.
Thank you.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2016-12-17 23:21:11 - In reply to message 1 from Leandro Siow
The response may be decoded depending on the Content-Type header returned by the server.
What is the response Content-Type value that the server returns? Set debug to true and check PHP error log to see what is returned.
You can override the response content type using ResponseContentType parameter set to 'application/json' in case it returns something different.
Just let me know if it works for what you mean.
![Picture of Leandro Siow Picture of Leandro Siow](/graphics/unknown.gif) Leandro Siow - 2016-12-18 00:51:19 - In reply to message 2 from Manuel Lemos
Hi,
thanks for the quick reply.
Most of my calls are to Twitter and Facebook, and I believe their return type is in JSON format. However when I do CallAPI, the functions is returning an Array instead of JSON which was returned by Facebook or Twitter?
Would I still need to look into the Content-Type?
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2016-12-18 02:10:15 - In reply to message 3 from Leandro Siow
No, for instance Facebook returns application/json, so the class will automatically decode the JSON response with json_decode() and returns a stdClass object, not the actual JSON string.
Do you want the JSON string?
If you try the Facebook example it returns an object like this? Isn't it this that appears for you?
stdClass Object
(
[id] => 628216645
[first_name] => Manuel
[gender] => male
[last_name] => Lemos
[link] => https://www.facebook.com/app_scoped_user_id/628216645/
[locale] => en_US
[name] => Manuel Lemos
[timezone] => -2
[updated_time] => 2016-10-17T03:04:57+0000
[verified] => 1
[email] => mlemos@email.com
)
![Picture of Leandro Siow Picture of Leandro Siow](/graphics/unknown.gif) Leandro Siow - 2016-12-18 02:55:38 - In reply to message 4 from Manuel Lemos
Yes sir
it appears correctly as:
stdClass Object
(
[id] => 628216645
[first_name] => Manuel
[gender] => male
[last_name] => Lemos
[link] => https://www.facebook.com/app_scoped_user_id/628216645/
[locale] => en_US
[name] => Manuel Lemos
[timezone] => -2
[updated_time] => 2016-10-17T03:04:57+0000
[verified] => 1
[email] => mlemos@email.com
)
And yes you are right again, I am looking for the JSON String:
{ "id" = 628216645
"first_name" = XXX
}
before it gets decoded.
Would that be possible?
Thank you for supporting this API btw it is just awesome.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2016-12-18 04:19:43 - In reply to message 5 from Leandro Siow
If you set the ResponseContentType parameter to 'application/octet-stream', it will return it as if it is some binary data, so it will not be decoded.
Anyway, why you want to the original JSON before being decoded? Just let me know so I can figure it is something that I can improve.
![Picture of Leandro Siow Picture of Leandro Siow](/graphics/unknown.gif) Leandro Siow - 2016-12-18 20:19:07 - In reply to message 6 from Manuel Lemos
Oh cool yeah when I sent the Content-Type to application/octet-stream, i get the full json data.
[
{
"created_at": "Sun Dec 18 14:00:06 +0000 2016",
....
}
]
I know that eventually it needs to be decoded into an array, so that it can be used. I was thinking of interoperability. For example if I am writing an Android or iOS app, I can use the same php page to output json to these apps when they make the call.
That was what I was thinking.
I am not sure if this is the "industry standard" but I do get the JSON file now, once the content-type was set to application/octet.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2016-12-18 23:17:29 - In reply to message 7 from Leandro Siow
I see, use PHP as a proxy. Makes sense.
![Picture of Leandro Siow Picture of Leandro Siow](/graphics/unknown.gif) Leandro Siow - 2016-12-19 21:13:11 - In reply to message 8 from Manuel Lemos
exactly :D
Then even Javascripts can make AJAX calls to the PHP as well and process the JSON.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2016-12-20 04:26:22 - In reply to message 9 from Leandro Siow
Yes, that is true, it is more secure to use PHP as proxy for getting tokens.
I may write an article on that. Thanks for the feedback.
|