Consuming an API field

Associate
Joined
16 Apr 2007
Posts
2,208
Code:
 $.ajax({
            url:  'https://api.flickr.com/services/feeds/photos_public.gne?tags=potato&tagmode=all&format=json&nojsoncallback=1',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            type: 'GET',
            success:function (response, textStatus, jqXHR) {                
                alert(response.title)
            },
            error: function (jqXHR, textStatus, errorThrown) {

            }
        });
Something like that. But you may have issues with access-control-allow-origin headers.
 
Last edited:
Associate
OP
Joined
10 Jan 2006
Posts
483
Hmm doesnt seem to work I am getting an error - I have solved the CORS issue so thats not a problem.

What I don't understand it why the web page does not look like a normal JSON page
 
Associate
OP
Joined
10 Jan 2006
Posts
483
SyntaxError: Unexpected token '
at Object.parse (native)

I was getting a response fine with the previous but for some reason it doesnt like the jsoncallback=1..
 
Associate
OP
Joined
10 Jan 2006
Posts
483
Code:
this.getPhoto = function(){
    console.log('gettinghere')
    $http
    .get('https://api.flickr.com/services/feeds/photos_public.gne?tags=potato&tagmode=all&format=json&nojsoncallback=1')
    .then(function(response){
      var photoData = response.data
      console.log(photoData)
      self.addPhoto(photoData)
    })
    // self.newPhoto = '';
  }

  self.addPhoto = function(photoData){

    var newPhotoObject = {
      title: photoData['title']
    }
    // console.log(newPhotoObject)
    self.photos.push(newPhotoObject);
    var newPho = new Photo(newPhotoObject);
    newPho.$save(function(){
      newPhotoObject = {}
    });
  }
 
Associate
Joined
24 May 2011
Posts
262
Have you incorporated the code I had in the jsfiddle into your angular solution? If so can you post that code?
 
Associate
Joined
24 May 2011
Posts
262
I get the following error when running your js fiddle:

Uncaught Error: [$injector:modulerr] Failed to instantiate module flickrApp due to:
Error: [$injector:nomod] Module 'flickrApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
 
Associate
OP
Joined
10 Jan 2006
Posts
483
that's weird I have never put angular in JS fiddle before - It seems to think the flickrApp does not exist - but I defined it in the JS at the top and in the HTML
 
Back
Top Bottom