3

here i try to fetch json data from following url

https://www.flickr.com/services/api/render?method=flickr.places.find&api_key=xxxxx&query=$search_data&format=json&nojsoncallback=1

contain following information which i want to get according above link

{
    "places": {
        "place": [
            {
                "place_id": "Dm5SiT1TULMEIMYN",
                "woeid": "2295402",
                "latitude": 23.03,
                "longitude": 72.591,
                "place_url": "/India/Gujarat/Ahmedabad",
                "place_type": "locality",
                "place_type_id": 7,
                "timezone": "Asia/Kolkata",
                "_content": "Ahmedabad, Gujarat, India",
                "woe_name": "Ahmedabad"
            },
            {
                "place_id": "mz1zSK1YUrJTfvUrOA",
                "woeid": "90883450",
                "latitude": 23.027,
                "longitude": 72.57,
                "place_url": "/India/Gujarat",
                "place_type": "locality",
                "place_type_id": 7,
                "timezone": "Asia/Kolkata",
                "_content": "Ahmedabad, India",
                "woe_name": "Ahmedabad"
            }
        ],
        "query": "Ahmedabad, Gujarat, India",
        "total": 2
    },
    "stat": "ok"
}

but here problem is that this link return null i'm using following code of php

$json_array = file_get_contents("https://www.flickr.com/services/api/render?method=flickr.places.find&api_key=xxxxx&query=Ahmedabad,%20Gujarat,%20India&format=json&nojsoncallback=1");
$json_array = iconv('UTF-16', 'UTF-8', $json_array);
$json_data=json_decode($json_array,true);
print_r($json_data);
4
  • When I echo $json_array I get an HTML document. Commented Feb 9, 2015 at 8:43
  • yes that's right but i want to get json data Commented Feb 9, 2015 at 8:45
  • So either find a URL that gives you a JSON document, or parse the HTML. Commented Feb 9, 2015 at 8:45
  • I added a $ symbol to print_r($json_data); not sure if that was an issue in your actual code or not though. Commented May 9, 2016 at 23:11

3 Answers 3

2

Your call is wrong. The correct one would be

https://api.flickr.com/services/rest/?method=flickr.places.find&.....
Sign up to request clarification or add additional context in comments.

5 Comments

I have checked too. But how it explains why json_decode doesn't decodes json? I have checked json with validator and it's correct.
@RomanLosev The OP didn't use the rest endpoint of the flicker API. He used the rendering endpoint, which syntax highlights the JSON via HTML. json_decode can not decode HTML. Thus it failed.
yes but doesn't get information how to get perticular information like i want to fetch place_id how?
You're welcome. You might want to mark this answer as correct, so it is easier for other people to find that face a similiar problem
2

I found it, its because you are calling /api/render method of API so it will give pretty printed json

just use this url instead

//https://www.flickr.com/services/rest?method=flickr.places.find&api_key=c5336c8cc248142bbda940c1f771bfd5&query=Ahmedabad,%20Gujarat,%20India&format=json&nojsoncallback=1

$json_array = file_get_contents("https://www.flickr.com/services/rest?method=flickr.places.find&api_key=c5336c8cc248142bbda940c1f771bfd5&query=Ahmedabad,%20Gujarat,%20India&format=json&nojsoncallback=1");

$json_data=json_decode($json_array,true);
print_r($json_data);

Comments

1

I tried a sample request from the Flickr API.

https://www.flickr.com/services/rest/?method=flickr.test.echo&format=json&foo=bar&api_key=cddc3ae537ed443aafa20cf2c30086df

You need to add the following parameter format=json in your request URI. Also, the endpoint must be /services/rest.

2 Comments

yes that's fine but i can't scrap code of particular id information such as place_id how?
If you have received the JSON now (use whatever URL you were using), you could just use json_decode($response, true). This will convert the respone into the PHP array object. Then you can iterate over all the responses.

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.