简体   繁体   English

访问令牌密钥和秘密在DropNet中不起作用

[英]Access token key and secret not working in DropNet

I'm using DropNet for Dropbox OAuth but I have one major problem - I can't store access token key and secret cause there is no point storing them. 我正在使用DropNet for Dropbox OAuth,但我有一个主要问题 - 我无法存储访问令牌密钥和秘密因为没有点存储它们。 The storing mechanism is not a problem and not a key problem here - the problem is in this: 存储机制不是问题,而不是一个关键问题 - 问题在于:

private void dropboxUpload()
{
    DropNetClient _Dclient = new DropNetClient("xxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyy");
    _Dclient.UseSandbox = true;
    if (!dropboxLoggedIn)
    {
            _Dclient.GetToken();
            string url = _Dclient.BuildAuthorizeUrl();
            Process.Start(url);
            if (MessageBox.Show("Click OK after you have allowed Sizester to create and access a sub-folder called Sizester in a folder called Apps in your Dropbox account.", "Sizester access request", MessageBoxButtons.OKCancel) != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
        }
        try
        {
            if (!dropboxLoggedIn)
            {
                _Dclient.GetAccessToken();
                dropboxAsecret = _Dclient.UserLogin.Secret;
                dropboxAtoken = _Dclient.UserLogin.Token;
            }
            else
            {
                _Dclient.UserLogin.Token = dropboxAtoken;
                _Dclient.UserLogin.Secret = dropboxAsecret;
            }
            dropboxLoggedIn = true;
            //...
            _Dclient.UploadFile("/", fileE, FileToByteArray(newFilePath));
            MessageBox.Show("Successfully uploaded to Dropbox.", "Uploaded to Dropbox");
        }
        catch (Exception dropboxEx)
        {
            MessageBox.Show("Error: " + dropboxEx.Message);
        }
    }

The problem here is - first time it uploads ok, but the second time it doesn't - although dropboxLoggedIn is true, and access token key and secret are stored ok, it doesn't upload file, but more strangely it doesn't return any error or exception. 这里的问题是 - 第一次上传确定,但第二次没有 - 虽然dropboxLoggedIn是真的,访问令牌密钥和秘密存储好,它不上传文件,但更奇怪的是它不返回任何错误或异常。 If I move GetToken out of if same thing happens. 如果我移动GetToken,如果同样的事情发生。 I know I'm doing somewhere wrong, but I can't quite get where. 我知道我做错了什么,但我不能到达哪里。 I've striped some parts of code like file paths and getting the file which are irrelevant. 我已经对文件路径的某些部分进行了条带化​​处理,并获取了与之无关的文件。 I did the same thing for Twitter, but it works there with no problems. 我为Twitter做了同样的事情,但它没有任何问题。 Any ideas? 有任何想法吗?

This link should help with that issue: http://forums.dropbox.com/topic.php?id=61115&replies=6 此链接应该有助于解决该问题: http//forums.dropbox.com/topic.php?id = 61115&replies = 6

Basically you need to initialize your DropNetClient _Dclient instance out of the Upload File method. 基本上,您需要从Upload File方法初始化DropNetClient _Dclient实例。 When you got access token you should keep it in your session or config file and you won't need to do it every time you upload file. 当您获得访问令牌时,您应将其保存在会话或配置文件中,并且每次上传文件时都不需要这样做。

From the looks of that line 3 is messing you up: if (!dropboxLoggedIn) 从那条线3的外观搞砸了你: if (!dropboxLoggedIn)

So you are only continuing if the user is not logged in but on the 2nd attempt your saying that should be true, thus skipping all of your upload code. 因此,只有当用户未登录时才会继续,但在第二次尝试时,您的说法应该是真的,从而跳过所有上传代码。

Ok, so the problem was in initialization of the object - if you do: 好的,所以问题在于对象的初始化 - 如果你这样做:

DropNetClient _Dclient = new DropNetClient("xxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyy");
_Dclient.UseSandbox = true;
_Dclient.UserLogin.Token = "zzzzzzzzzzzzzzz";
_Dclient.UserLogin.Secret = "wwwwwwwwwwwwww";

This wouldn't work - instead it needs to be initialized like this: 这不起作用 - 而是需要像这样初始化:

DropNetClient _Dclient = new DropNetClient("xxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyy","zzzzzzzzzzzzzzz","wwwwwwwwwwwwww");
_Dclient.UseSandbox = true;

I'm not sure where I found the first code sample in some documentation or forum but it's wrong. 我不确定在某些文档或论坛中我找到第一个代码示例的位置,但这是错误的。 If you use it - no error or exception will happen, but dropbox file upload or operation won't be done. 如果您使用它 - 不会发生错误或异常,但不会完成Dropbox文件上传或操作。 If you use the second one all will work. 如果你使用第二个,那么一切都会有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM