你如何从 Imgur 获得 access_token 和 refresh_token?

How do you get access_token and refresh_token from Imgur?

我正在使用的项目:来自 nuget 的 ImgurNet(来源:https://github.com/0xdeafcafe/ImgurNet

它似乎需要所有这些参数:

{
    "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"
}

...在 imgur 中我只能得到 client_id + client_secret.

Imgur API 文档提到了这些,但没有说明如何获取它们:https://api.imgur.com/oauth2


额外的细节:

我使用 ImgurNet 因为它是我唯一能够在我的 Xamarin 项目中安装的 imgur api nuget 包(所有其他的都不兼容)。

这是我使用的代码示例:

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;

抛出的异常是"Your OAuth AccessToken has expired"(然后我用完全相同的结果刷新了client_secret)。

来自 imgur 文档:

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.

...所以无论如何 refresh_token 似乎都是必要的。

编辑:问题被误解了。

获取 access_token 的说明位于 API 文档 link 的 "Authorization" 部分,您提供:

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

编辑 2:

API 文档还有一个方便的 table,它解释了参数是什么以及您可以使用哪些可能的值:

如果您已经有了 ID 和密码,只需在

上使用浏览器登录即可

https://imgur.com/

然后在另一个选项卡上输入此 URL(替换 CLIENT_ID)

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

接受(看起来像 this,然后从结果中 URL 您需要提取所需的标记或详细信息。

很多地方解释的很绕,就是这么简单。

关于 https://rapidapi.com/blog/imgur-api-tutorial/

的一些额外信息