Dropbox的获取访问令牌Dropnet [英] Getting Dropbox Access Token With Dropnet

查看:490
本文介绍了Dropbox的获取访问令牌Dropnet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现我的网站上的文件上传到Dropbox的。不过,我遇到麻烦的accessToken用户点击授权我的应用程序了。

I'm attempting to implement file uploading to Dropbox on my site. However, I'm having trouble getting the accessToken after the user clicks to authorize my app.

下面是我的code抢URL,这将会返回给客户端在Javascript中打开一个新的窗口。

Here is my code to grab the URL, which gets returned to the client to open a new window in Javascript.

[WebMethod]
public String setUpDropboxOA(String uri, Int32 form_id, String user_auth)
{
    var client = new DropNetClient("xxxxxxxxx", "xxxxxxxxx");
    return client.GetTokenAndBuildUrl(uri);
}

这是我的回调函数:

And here is my callback function:

[WebMethod]
public void AuthorizeDropboxCallback(String oauth_token)
{
    var client = new DropNetClient("xxxxxxxxx", "xxxxxxxxx");
    var accessToken = client.GetAccessToken();
    var jsonObj = new { oauth_token = accessToken.Token, oauth_secret = accessToken.Secret };
    var JSONAuthorizationData = JsonConvert.SerializeObject(jsonObj);
    saveNotification(form_hash, "Dropbox", JSONAuthorizationData, user_id);
}

这是我收到的client.GetAccessToken()错误:

And here is the error that I'm getting on client.GetAccessToken():

Exception of type 'DropNet.Exceptions.DropboxException' was thrown.

DropNet的文件说,有一个过载GetAccessToken,将允许您指定一个令牌使用,但是,我没有看到的。我喜欢这种感觉这里的问题,但我不能完全肯定。

The documentation of DropNet says that there is an overload to GetAccessToken that will allow you to specify a token to use, however, I'm not seeing one. I feel like this is the problem here, but I'm not entirely sure.

推荐答案

作为@ albattran的回答表明那是因为你正在创建的DropNetClient 2个不同的实例。

As @albattran's answer suggested it is because you are creating 2 different instances of the DropNetClient.

client.GetTokenAndBuildUrl(URI);

Thismethod实际上做的引擎盖下两件事情。 1,使API调用的Dropbox获得请求令牌,然后使用该请求令牌它创建的登录URL。

Thismethod actually does 2 things under the hood. 1, Makes an API call to Dropbox to get a request token then using that request token it creates the login url.

要解决这个问题,你需要一种方法来存储Web请求之间的请求令牌。

To solve this you will need a way to store that request token between web requests.

也许想想下面使用会话类似的。

Maybe think about something like the below using the session.

var userToken = client.GetToken();
Session["user_token"] = userToken.Token;
Session["user_secret"] = userToken.Secret;

然后确定回调阅读这些会话变量,并将它们添加到DropNetClient的构造函数重载。

Then ok the callback read those session variables and add them to the constructor overload of the DropNetClient.

var token = Session["user_token"];
var secret = Session["user_secret"];
var client = new DropNetClient("XXXX", "XXXX", token, secret);
client.GetAccessToken();

这篇关于Dropbox的获取访问令牌Dropnet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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