MVC上的Dropnet在第一次通话时未经授权

时间:2014-11-28 11:02:07

标签: c# dropbox dropbox-api dropnet

我正在使用以下代码,该代码仅适用于我的第二次尝试。当我第一次使用它时,它总是获得未经授权,下次调用它会成功运行。

public ActionResult AuthorizeDropBox(string redirectUrl)
{
        var _client = new DropNetClient("XXXX", "XXXX");
        if (_client == null)
            throw new DropboxException();

        var userLogin = _client.GetToken();
        var url = _client.BuildAuthorizeUrl(Url.Action("DropBoxCallBack", "Home", null, Request.Url.Scheme));

        Session["UserToken"] = userLogin.Token;
        Session["UserSecret"] = userLogin.Secret;

        return Redirect(url);
}

public ActionResult DropBoxCallBack()
{
    var userToken = Session["UserToken"];
    var userSecret = Session["UserSecret"];

    var _client = new DropNetClient("XXXX", "XXXX", userToken.ToString(), userSecret.ToString());
    if (_client == null)
        throw new DropboxException();

    var userLogin = _client.GetAccessToken();

    var file = _client.GetFile("/Getting Started.pdf");

    return RedirectToAction("Index", "Home");
}

有什么想法吗?

谢谢

0 个答案:

没有答案