Xav*_*eña 4 .net c# imgur xamarin
我正在使用的项目:来自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"
}
Run Code Online (Sandbox Code Playgroud)
...而在 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;
Run Code Online (Sandbox Code Playgroud)
抛出的异常是“您的 OAuth AccessToken 已过期”(然后我刷新了client_secret完全相同的结果)。
来自 imgur 文档:
如果用户已授权其帐户,但您不再拥有其有效的 access_token,则可以使用刷新令牌生成新的 access_token。
...所以refresh_token无论如何似乎都是必要的。
如果您已有 ID 和密码,只需使用浏览器登录即可
然后在另一个选项卡上输入此 URL(替换 CLIENT_ID)
https://api.imgur.com/oauth2/authorize?client_id=CLIENT_ID&response_type=token
接受(如下图所示),您需要从生成的 URL 中提取所需的标记或详细信息。
很多地方都以非常复杂的方式解释它,但事实就是这么简单。
https://rapidapi.com/blog/imgur-api-tutorial/上的一些额外信息
注意:这适用于任何编程语言。Q 提到了 C#,但我使用 bash 和 python 来连接 Imgur。