我注册了Imgur API并注册了一个测试应用程序并重新获得了客户端ID和客户端密钥。
然后我尝试使用此代码:
try {
var image = canvas.toDataURL('image/jpeg', 0.9).split(',')[1];
} catch(e) {
var image = canvas.toDataURL().split(',')[1];
}
// upload to imgur using jquery/CORS
// https://developer.mozilla.org/En/HTTP_access_control
$.ajax({
url: 'http://api.imgur.com/2/upload.json',
type: 'POST',
data: {
type: 'base64',
// get your key here, quick and fast http://imgur.com/register/api_anon
key: '123',
name: 'neon.jpg',
title: 'test title',
caption: 'test caption',
image: image
},
dataType: 'json'
}).success(function(data) {
window.location.href = data['upload']['links']['imgur_page'];
}).error(function() {
alert('Could not reach api.imgur.com. Sorry :(');
window.close();
});
我找到here将图片上传到Imgur。我用我的客户端ID替换了上面示例中的“123”,但是ajax响应返回错误“无效的API密钥”。我没有收到API密钥,但是没有收到客户端ID和客户端密钥。我尝试了2的变种,但仍然没有运气。如何解决这个过去的API密钥问题?上面的代码也是过时的,因为我认为有一个版本3的API,但似乎只适用于https,我的网站上没有SSL。