Ich bin ein neuer Programmierer und ziemlich neu zu .js
im Allgemeinen. Meine aktuelle Problem ist, dass, wenn ich dieses Skript ausführen Instagram.popular(function(r){ console.log(r)})
lokal (dh auf der Konsole von Firefox) bekomme ich folgende Fehler The access_token provided is invalid
Instagram API Das angegebene access_token ist ungültig
Wie ich in GitHub und anderen Orten lesen, es hat etwas zu tun mit Instagram einige API Änderung der Politik wie diskutiert here. Das Änderungsprotokoll für Instagram wird here gegeben.
Wenn mir jemand in die richtige Richtung zeigen kann, werde ich es sehr schätzen.
Unten können Sie meinen vollen .js
Code sehen.
CODE
window.Instagram = {
/**
* Store application settings
*/
config: {},
BASE_URL: 'https://api.instagram.com/v1',
init: function(opt) {
opt = opt || {};
this.config.client_id = opt.client_id;
},
/**
* Get a list of popular media.
*/
popular: function(callback) {
var endpoint = this.BASE_URL + '/media/popular?client_id=' + this.config.client_id;
this.getJSON(endpoint, callback);
},
/**
* Get a list of recently tagged media.
*/
tagsByName: function(name, callback) {
var endpoint = this.BASE_URL + '/tags/' + name + '/media/recent?client_id=' + this.config.client_id;
this.getJSON(endpoint, callback);
},
getJSON: function(url, callback) {
$.ajax({
type: 'GET',
url: url,
dataType: 'jsonp',
success: function(response) {
if (typeof callback === 'function') callback(response);
}
});
}
};
Instagram.init({
client_id: '97bf259cc45f4dd6a2cd02b694b7ffe7'
});
$(document).ready(function() {
Instagram.popular(function(response) {
var $instagram = $('#instagram');
for (var i = 0; i < response.data.length; i++) {
imageUrl = response.data[i].images.low_resolution.url;
$instagram.append('<img src="' + imageUrl + '" />');
}
});
$('#form').on('submit', function(e) {
e.preventDefault();
var tagName = $('#search').val();
Instagram.tagsByName(tagName, function(response) {
var $instagram = $('#instagram');
$instagram.html('');
for (var i = 0; i < response.data.length; i++) {
imageUrl = response.data[i].images.low_resolution.url;
$instagram.append('<img src="' + imageUrl + '" />');
}
});
});
});