How do you get access_token and refresh_token from Imgur?

[亡魂溺海] 提交于 2020-01-23 10:01:30

问题


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.


回答1:


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:



来源:https://stackoverflow.com/questions/37486480/how-do-you-get-access-token-and-refresh-token-from-imgur

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!