使用 Angular 访问 Instagram API 的喜欢图片
Accessing liked images of instagram API with Angular
我正在尝试访问特定 instagram 用户喜欢的媒体的 JSON,在文档中它说要使用这个:
https://api.instagram.com/v1/users/self/media/liked?access_token=ACCESS-TOKEN
如此处所述:
https://instagram.com/developer/endpoints/users/
将 ACCESS-TOKEN 替换为我在下面完成的 instagram 提供的那个:
(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)
});
});
})();
显然我已经用我的替换了 ACCESS-TOKEN,但是什么都没有返回,有什么不正确的地方吗?
编辑:我添加了回调,但它仍然未定义。
它是 jsonp,所以我的猜测是您应该 在 URL:
中指定回调函数的名称
var endpoint = "https://api.instagram.com/v1/users/self/media/liked/?callback=callback";
要使用 jsonp 完成这项工作,请将以下内容添加到您的端点 url:
&callback=JSON_CALLBACK
您的回调需要命名为 'JSON_CALLBACK'。在这里找出原因:https://docs.angularjs.org/api/ng/service/$http#jsonp
否则,要发出一个简单的 GET 请求...
$http.get(endpoint).success(function(data){
callback(data);
});
我正在尝试访问特定 instagram 用户喜欢的媒体的 JSON,在文档中它说要使用这个:
https://api.instagram.com/v1/users/self/media/liked?access_token=ACCESS-TOKEN
如此处所述: https://instagram.com/developer/endpoints/users/
将 ACCESS-TOKEN 替换为我在下面完成的 instagram 提供的那个:
(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)
});
});
})();
显然我已经用我的替换了 ACCESS-TOKEN,但是什么都没有返回,有什么不正确的地方吗?
编辑:我添加了回调,但它仍然未定义。
它是 jsonp,所以我的猜测是您应该 在 URL:
中指定回调函数的名称var endpoint = "https://api.instagram.com/v1/users/self/media/liked/?callback=callback";
要使用 jsonp 完成这项工作,请将以下内容添加到您的端点 url:
&callback=JSON_CALLBACK
您的回调需要命名为 'JSON_CALLBACK'。在这里找出原因:https://docs.angularjs.org/api/ng/service/$http#jsonp
否则,要发出一个简单的 GET 请求...
$http.get(endpoint).success(function(data){
callback(data);
});