您如何从Imgur获得access_token和refresh_token? [英] How do you get access_token and refresh_token from Imgur?

查看:73
本文介绍了您如何从Imgur获得access_token和refresh_token?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的项目:nuget的ImgurNet(来源:

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.

解决方案

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:

这篇关于您如何从Imgur获得access_token和refresh_token?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆