how to get correct JSON object from flickr API

ankitr picture ankitr · Jul 10, 2014 · Viewed 11k times · Source

I used flickr photo search method to retrieve public photos. when I run it with jquery, it works fine, I get the json object in correct form.

{
    "photos": {
        "photo": [
            {
              .........
            }
        ]
    },
    "stat": "ok"
}

But when I use it with AngularJs, I got the same object with a prefix jsonFlickrApi

jsonFlickrApi({
    "photos": {
        "photo": [
            {
               ...... 
            }
        ]
    },
    "stat": "ok"
})

what I used in AngularJs is:

myApp.service('dataService', function($http) {
    delete $http.defaults.headers.common['X-Requested-With'];
    this.flickrPhotoSearch = function() {
        return $http({
            method: 'GET',
            url: 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=3f807259749363aaa29c2fa93945&tags=india&format=json&callback=?',
            dataType: 'json'
         });
     }
});

Please tell me how can I convert the second JSON to the first one. Is there anything I can do in $http call or have to alter JSON object.

Answer

ankitr picture ankitr · Aug 26, 2014

There was problem in the url. This Url works for me.

https://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=3f807259749363aaa29c712fa93945&user_id=61495424@N00&format=json&nojsoncallback=?