4

Project I am using: ImgurNet from nuget (source: https://github.com/0xdeafcafe/ImgurNet)

It seems like it needs all those parameters:

{
    "client_id": "Insert your imgur client_id here",
    "client_secret": "Insert your imgur client_secret here",
    "access_token": "Insert your imgur access_token here", 
    "refresh_token": "Insert your imgur refresh_token here",
    "authorized_username": "Insert your imgur username here"
}

...while in imgur I am only able to get client_id + client_secret.

The Imgur API documentation mentions those, but doesn't say how to get them: https://api.imgur.com/oauth2


Extra details:

I use ImgurNet because it is the only imgur api nuget package that I've been able to install in my Xamarin project (all the other ones were not compatible).

This is an example of the code I'm using:

var oauth2Authentication = new OAuth2Authentication("my_client_id", "my_client_secret", false);
var imgurClient = new Imgur(oauth2Authentication);            
var imageEndpoint = new ImageEndpoint(imgurClient);
var result = imageEndpoint.UploadImageFromBinaryAsync(imageBinary, title: "my title", description: "my description").Result;

And the exception thrown is "Your OAuth AccessToken has expired" (I then refreshed the client_secret with the exact same result).

From the imgur documentation:

If a user has authorized their account but you no longer have a valid access_token for them, then a new one can be generated by using the refresh_token.

...so refresh_token seems necessary regardless.

Xavier Peña
  • 7,399
  • 9
  • 57
  • 99
  • @Sylverac That's what I did, and I obtained `client_id` and `client_secret`, but not `access_token` and `refresh_token`. – Xavier Peña May 27 '16 at 14:57
  • I'm an idiot and misread your question, sorry. – Lews Therin May 27 '16 at 14:57
  • @Sylverac No problem, thanks for trying to help. I'll leave the answer to the comment as clarification to other readers. – Xavier Peña May 27 '16 at 14:59
  • Although, the instructions for getting an `access_token` is in the "Authorization" section: "To access a user's account, the user must first authorize your application so that you can get an access token. Requesting an access token is fairly straightforward: point a browser (pop-up, or full page redirect if needed) to a URL and include a set of query string parameters." `https://api.imgur.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=REQUESTED_RESPONSE_TYPE&state=APPLICATION_STATE` – Lews Therin May 27 '16 at 15:00
  • I'm genuinely not trying to be a jerk, but the instructions are all there in the API documentation link you provided. Re-read it carefully and then post specific questions/problems you are having and I'd be happy to help. – Lews Therin May 27 '16 at 15:03

2 Answers2

4

If you already have the id and secret, just login with your browser on

https://imgur.com/

and then on another tab enter this URL (replace CLIENT_ID)

https://api.imgur.com/oauth2/authorize?client_id=CLIENT_ID&response_type=token

Accept (looks like this, and from the resulting URL you need to extract the desired tokens or details.

It is explained in very convoluted ways in many places and it is just that simple.

Some extra info on https://rapidapi.com/blog/imgur-api-tutorial/

Rub
  • 2,071
  • 21
  • 37
3

Edit: misunderstood question.

The instructions for getting an access_token is in the "Authorization" section of the API documentation link you provided:

To access a user's account, the user must first authorize your application so that you can get an access token. Requesting an access token is fairly straightforward: point a browser (pop-up, or full page redirect if needed) to a URL and include a set of query string parameters. https://api.imgur.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=REQUESTED_RESPONSE_TYPE&state=APPLICATION_STATE

Edit 2:

The API documentation also has a handy table that explains what the parameters are and what possible values you can use:

params

Lews Therin
  • 3,707
  • 2
  • 27
  • 53
  • This might be it, but I am having a hard time trying to successfully apply the query. I don't understand the parameters `REQUESTED_RESPONSE_TYPE` (I have tried `json` just to try it) and `APPLICATION_STATE` are unknown to me. And I don't seem to find any documentation about them. The json response in my tests is always `{"data":{"error":null,"request":"\/oauth2\/authorize","method":"POST"},"success":false,"status":400}` (so "not succeeded"). – Xavier Peña May 27 '16 at 15:16
  • @XavierPeña Once more, *read the documentation*. Take a second and really read all of it. The answers you are looking for are there. In that same Authorization section, they have a table that outlines what the parameters are and what possible values you can use for them. Ex: "`response_type`, values: `code`, `token`, or `pin`, Determines if Imgur returns an authorization_code, a PIN code, or an opaque access_token. If you choose code ..." – Lews Therin May 27 '16 at 15:21
  • I've updated my answer to include the table I was referring to. Hope this helps. – Lews Therin May 27 '16 at 15:24
  • 1
    Thanks! The final URL that was needed for what I was looking for `https://api.imgur.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=token`. It is a bit confusing since one does not expect the server answer to be in the URL of the page it redirects you to. It took me some seconds to realize that, I thought the query failed again. Thank you very much for your help, I am marking it as answered. – Xavier Peña May 27 '16 at 15:36
  • @XavierPeña No problem, glad you got it resolved. Happy coding! :) – Lews Therin May 27 '16 at 15:36
  • what would you have for application_string? can you please provide an example? – Mona Jalal Oct 18 '16 at 01:31
  • @LewsTherin I keep getting this error: `{"data":{"error":"Imgur is temporarily over capacity. Please try again later."},"success":false,"status":500}` – Mona Jalal Oct 18 '16 at 01:33