I'm working on a simple enough website and I need to perform a get request to Imgur's API. Using the following works fine:
curl -v --location --request GET 'https://api.imgur.com/3/album/WFWR56Z/images' \
--header 'Authorization: Client-ID {{clientId}}'
As does the following Python 3 code:
import requests
url = "https://api.imgur.com/3/album/WFWR56Z/images"
headers = {
'Authorization': 'Client-ID {{clientId}}'
}
response = requests.request("GET", url, headers=headers, data=payload)
Setting up a simple example and serving it on local host using Apache and fetch also works:
var myHeaders = new Headers();
myHeaders.append("Authorization", "Client-ID {{clientId}}");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://api.imgur.com/3/album/WFWR56Z/images\n", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
However, when I use Angular's HttpClient like so:
constructor(private http: HttpClient) { }
getImageLinks(): void {
const headers = new HttpHeaders(
{
'Authorization': "Client-ID {{clientId}}",
});
this.http.get("https://api.imgur.com/3/album/WFWR56Z/images", { headers }).subscribe(data => {
console.log(data);
})
}
}
I almost always get a 429 rate limit error. There are rare times when this doesn't occur, but I can't seem to identify when and why it manages to return.