Im hitting this url
https://graph.facebook.com/1843624489016097?fields=link&access_token=EAAD3ZBKkIhYMBAL3KRi9eZBXlYJADZARRFMSe0Nc35WTP92X2etkccVqnjNcjJgKbd8ABtX5pyDPN0nAA7jORyjpOGexZCYp1Sf2iw0DJjCf8UkPiLwhuApSGDGZBvy5w7vk3U0Ba97FZA2DO7J4m4UjvbIolDaRP9TRpemEmLyQZDZD
with the below code in php,
$url ='https://graph.facebook.com/' . $connection->provider_id . '?fields=link&access_token=' . $connection->token;
$ch = curl_init($url);
$json= curl_exec ($ch);
I have this html coming from Facebook, I want to use only “Link” in this,
{"link":"https://www.facebook.com/app_scoped_user_id/YXNpZADpBWEdrUlJiUzc0SWFWZATI4SEVJUmJHTTJQVHU2M3owcTJLOHh5MnJYOTI0LWdMT3VFUC1veXNWdXBhM3o3RzdkQmV4cjNfTC1nSkdheGFhV19pWWU5T1ZAWSzlkN0NBTUl4NVZAKTE9oRjlFbjdObU5i/","id":"1686741234967769"}1
I tried converting that into JSON but its not working, Its coming in same format, since im doing this in a API, im checking this under Postman, I did like this..
$request = json_encode($json, JSON_HEX_QUOT | JSON_HEX_TAG);
The format is not getting convert to json, Im doing in PHP Laravel.
2
Answers
You should use json_decode in place of json_encode. So you should try like:
Also use
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
to save response in variable just aftercurl_init
.There’s a 1 at the end of the output, possibly you’re echoing something extra that you shouldn’t .
I suspect you expect curl to return the actual result but you are not using the appropriate flag. The reason I suspect that is because you are assigning the return result to
$json
but without the flagCURLOPT_RETURNTRANSFER
will returntrue
and not any json value.Here’s what you can try:
More information on the curl flags in the manual