Adding the Client and user rate header fields to the Access-Control-Allow-Headers ?

19 views
Skip to first unread message

RepostStatistics

unread,
Apr 12, 2015, 6:21:23 PM4/12/15
to im...@googlegroups.com
Hi,

I tried to get the user client rate for the api from an ajax request and realised i can't access the required headers (X-RateLimit-ClientRemaining...) due to them not being listed in the "Access-Control-Allow-Headers" header.
I am def. not an expert in this field, and maybe there is another way to get the use rate limits i didn't see (?).
But, if not, would it be possible to add these fields to the Access-Control-Allow-Headers header ?

Greetings Sleepprogger

@jasdev

unread,
Apr 14, 2015, 1:47:32 PM4/14/15
to im...@googlegroups.com
The rate-limiting headers are returned in the response. To inspect them via AJAX / JS, check out this example :)


Hope this helps!

Jasdev

RepostStatistics

unread,
Apr 14, 2015, 3:14:07 PM4/14/15
to im...@googlegroups.com
It seem to be a problem related to being a cross domain request. See http://stackoverflow.com/a/14689355for example.
Also it looks like the fields have to be listed in the "Access-Control-Expose-Headers" field not in the "Access-Control-Expose-Headers" field (Sry).

A little js snippet to test:
var CLIENT_ID = "YOUR_ID_IN_HERE";
var USER_NAME = "RepostStatistics";
$
.ajax({
  url
: 'https://api.imgur.com/3/account/'+USER_NAME + '/albums/count',
  method
: 'GET',
  headers
: {
   
Authorization: 'Client-ID ' + CLIENT_ID,
   
Accept: 'application/json'
 
},
  success
: function(data, status, request) {
    console
.log("All header i see: ", request.getAllResponseHeaders());
    console
.log("X-RateLimit-ClientRemaining : ", request.getResponseHeader("X-RateLimit-ClientRemaining"));
 
},
  error
: function(a, b, c){
    console
.log('Failed to load albums/count', a.status, a.responseText);
 
}
});


@jasdev

unread,
Apr 14, 2015, 4:13:13 PM4/14/15
to im...@googlegroups.com
Making the change now! In the mean time, you can use /3/credits to fetch rate-limit data :)

Thanks for pointing this out!

Jasdev

RepostStatistics

unread,
Apr 14, 2015, 4:40:13 PM4/14/15
to im...@googlegroups.com
Thank you.
If i should ever met you, i'll have to buy you  a beer  (or beverage of your choice) :)
I am going to use the credits endpoint for now (somehow completly overlooked it),

Have an awesome day.
SleepProgger
Reply all
Reply to author
Forward
0 new messages