Search code examples
angularimage-uploadingimgur

Getting stuck while trying to upload images to a specific user account in Imgur


I've created an Angular application which uploads images to Imgur. I've found ways to anonymously upload images to Imgur. I'm getting stuck when I'm trying to upload images to a specific user account.

Looking at the Imgur API and following the steps, I'm able to get the access token inside POSTMAN and then use the access token inside the header and send requests. I want to get the access token inside my application itself rather than posting requests inside POSTMAN. From what I've understood, for using it inside my application I need to make a call to:

https://api.imgur.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=REQUESTED_RESPONSE_TYPE&state=APPLICATION_STATE

How do I make the call to the above URL, get the response and then store the access_token from the response URL inside an Angular application. Because I've already tried sending GET request to the above URL inside Angular application and the above URL returns a HTML document and I didn't understand where to display this returned HTML document so I tried rendering it inside a DIV element which I think is a wrong choice. Now the HTML document is properly rendered inside the div element but the problem occurs when I'm trying to enter username and password inside the rendered HTML document, I get an error saying you cannot POST from 'https://localhost:4200/'.

I'm clearly doing something wrong and I don't understand how to make it work.


Solution

  • You should display/appeend returned html by following url in Modal dialog box instead of <div> tag. On Modal dialog box should POST to server.

    \https://api.imgur.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=REQUESTED_RESPONSE_TYPE&state=APPLICATION_STATE