I currently use the installed version of curl via exec() instead of using curl_exec() to query an API (linkedin). My call returns the good result but is weirdly encoded and I cannot transform it back to json.
Here is my code:
exec('curl "'.$url.'/v1/people/~?format=json" -H "Authorization: Bearer '.$token.'"', $data);
The response I get is (i replaced sensitive data with xxxx):
array(7) { [0]=> string(1) "{" [1]=> string(22) " "firstName": "xxxx"," [2]=> string(67) " "headline": "xxxx;"," [3]=> string(21) " "id": "xxxx"," [4]=> string(24) " "lastName": "xxxx"," [5]=> string(148) " "siteStandardProfileRequest": {"url": "https://www.linkedin.com/profile/view?id=xxxx&authType=name&authToken=xxxx&trk=apixxxxxxxx*"}" [6]=> string(1) "}" }
I've tried json_encode(json_decode($data)) but it doesn't change anything... How can I transform this output into a JSON object?
Why do I find the answer once I post it lol. Anyway just in case someone faces the same issue, I solved it with:
$data = implode('', $data);
$data = json_decode($data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With