0

Does Php have a method that calls a Json URL, and save in a variable the data it fetches for example can I used: "https://www.googleapis.com/blogger/v3/blogs/1/posts/"

I been trying with this code, but i am not sure if this is wrking

curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/blogger/v3/blogs/1/posts/");
curl_setopt($ch, CURLOPT_HEADER, 0);
$df = curl_exec($ch);
curl_close($ch);
6
  • "you're not sure this is working" well, then test it and tell us which is the EXACT problem you have. No connection? no data? wrong data? malformed data? how to parse the received data? at the moment it is not clear at all
    – STT LCU
    Commented Sep 12, 2014 at 14:30
  • the $df var has a true or false state, i expected the response data, i found the by google, and by that i dont understand at full what it does, that i seek help from coders who know what i wanted to do, and that part is clear, on top of that i been working with json for a short time, so as a started just wanted some help.
    – Shakavkav
    Commented Sep 12, 2014 at 14:37
  • It's still not clear what you want to achieve/which problem you have
    – STT LCU
    Commented Sep 12, 2014 at 14:40
  • and you took your time to down vote, while other for a change posted a solution, they did not seam to have a problem understanding,so once more i thank every one who came here to help
    – Shakavkav
    Commented Sep 12, 2014 at 14:47
  • yes, but the other answer is on a completely different topic, so your question was not clear. And I'm not the only one that thinks so.
    – STT LCU
    Commented Sep 12, 2014 at 14:54

2 Answers 2

4

You can use the bulti-in function json_decode http://php.net/manual/it/function.json-decode.php

$json = file_get_contents("https://www.googleapis.com/blogger/v3/blogs/1/posts/");
$obj = json_decode($json); //returns an object of json values
$array = json_decode($json, true); //returns an array of json values
1
  • Actually, that will return an object, not an array.
    – ʰᵈˑ
    Commented Sep 12, 2014 at 14:30
4

The problem is http*s*, try adding these:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
1
  • Thank you for posting a possible solution sir.
    – Shakavkav
    Commented Sep 12, 2014 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.