c# - 你如何从 Imgur 获取 access_token 和 refresh_token?

标签 c# .net xamarin 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;

抛出的异常是“您的 OAuth AccessToken 已过期”(然后我用完全相同的结果刷新了 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 文档链接的“授权”部分:

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 文档还有一个方便的表格,解释了参数是什么以及您可以使用哪些可能的值:

params

关于c# - 你如何从 Imgur 获取 access_token 和 refresh_token?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37486480/

相关文章:

c# - 跨应用钥匙串(keychain)访问,在哪里配置?

android - 使用 .NET 和 Visual Studio 2017 开发 Android OpenGL ES 应用程序

android - 带有图像的 Xamarin ListView 滚动不流畅

c# - 将 C# 连接到 MySQL 上的远程数据库

mysql - SQL 查询和线程

c# - 为什么 SubItems.Clear() 也会删除 Name 属性?

c# - 从当前登录用户的 Active Directory 中获取专有名称

C# .Net 文件在使用中的问题

c# - 线程 MVC 6 .net 5

c# - 使用 jquery 渲染局部 View