user1937021
user1937021

Reputation: 10811

Accessing liked images of instagram API with Angular

I'm trying to access the JSON of the liked media of a particular instagram user, in the documentation it says to use this:

https://api.instagram.com/v1/users/self/media/liked?access_token=ACCESS-TOKEN

as mentioned here: https://instagram.com/developer/endpoints/users/

replacing ACCESS-TOKEN with the one given by instagram which I've done below:

(function(){
      var app = angular.module('instafeed', []);
      app.factory("InstagramAPI", ['$http', function($http) {
        return {
          fetchPhotos: function(callback){
            var endpoint = "https://api.instagram.com/v1/users/self/media/liked/?";
            endpoint += "?access_token=[ACCESS-TOKEN]";
            endpoint += "&callback=JSON_CALLBACK";

            $http.jsonp(endpoint).success(function(response){
              callback(response);

            });
          }
        }
      }]);

      app.controller('ShowImages', function($scope, InstagramAPI){
        $scope.layout = 'grid';
        $scope.data = {};
        $scope.pics = [];

        InstagramAPI.fetchPhotos(function(data){
          $scope.pics = data;
          console.log(data)
        });
      });

    })();

obviously I have replaced ACCESS-TOKEN with mine, but nothing is given back, is there something incorrect?

EDIT: I added the callback but still it comes back as undefined.

Upvotes: 0

Views: 1793

Answers (2)

timsmiths
timsmiths

Reputation: 167

To make this work using jsonp, add the following to your endpoint url:

&callback=JSON_CALLBACK

Your callback needs to be named 'JSON_CALLBACK'. Find out why here: https://docs.angularjs.org/api/ng/service/$http#jsonp

Otherwise, to make a simple GET request...

$http.get(endpoint).success(function(data){
     callback(data);
});

Upvotes: 1

Stepan Suvorov
Stepan Suvorov

Reputation: 26236

It's jsonp, so my guess is that you should specify name of the callback function in your URL:

var endpoint = "https://api.instagram.com/v1/users/self/media/liked/?callback=callback";

Upvotes: 0

Related Questions