我想知道是否有人可以提供帮助。我使用DropNet客户端,并且我已成功使用Dropbox授权应用程序,并且我已将用户令牌和密码存储在SQL数据库中,因此我可以按如下方式再次访问它们:
public void Authenticated(Action success, Action<Exception> failure)
{
Client.GetAccessTokenAsync((accessToken) =>
{
UserToken = accessToken.Token;
UserSecret = accessToken.Secret;
UserAccountManagerBLL accBll = new UserAccountManagerBLL();
accBll.RememberMe(UserToken, UserSecret, Email);
if (success != null) success();
},
(error) =>
{
if (failure != null) failure(error);
});
我想要做的是在加载另一个表单时加载UserToken
和UserSecret
,这样我就可以拖放文件并上传到Dropbox,而无需再次使用Dropbox对应用程序进行身份验证。这是我如何加载令牌和秘密:
private void DropTray_Load(object sender, EventArgs e)
{
DropboxAccess dAccess = new DropboxAccess();
UserAccountManagerBLL accMan = new UserAccountManagerBLL();
UserToken = accMan.GetToken(Email);
UserSecret= accMan.GetSecret(Email);
if (UserToken == null && UserSecret == null)
{
MessageBox.Show(returnError());
}
else
{
Rectangle workingArea = Screen.GetWorkingArea(this);
this.Location = new Point(workingArea.Right - Size.Width,
workingArea.Bottom - Size.Height);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
}
}
此方法用于获取令牌
public string GetToken(string eMail)
{
using (cxn = new SqlConnection(this.ConnectionString))
{
using (cmd = new SqlCommand("spGetDetails", cxn))
{
cmd.CommandType = CommandType.StoredProcedure;
cxn.Open();
SqlDataReader dReader = cmd.ExecuteReader();
while (dReader.Read())
{
Utoken = dReader["UserToken"].ToString();
break;
}
dReader.Close();
cxn.Close();
}
}
return Utoken;
}
同样的秘密
一旦我拥有它们,我就有两个属性可以在页面加载时保存这些值:
public string UserToken { get; set; }
public string UserSecret { get; set; }
问题是我不知道如何让DropNet识别出我从数据库加载的这些值,我可以开始拖放文件了!?
更新:此处_Client
获取DropNet的用户令牌和密码:
private DropNetClient _Client;
public DropNetClient Client
{
get
{
if (_Client == null)
{
_Client = new DropNetClient(appKey, appSecret);
if (IsAuthenticated)
{
_Client.UserLogin = new UserLogin
{
Token = UserToken,
Secret = UserSecret
};
}
_Client.UseSandbox = true;
}
return _Client;
}
}
答案 0 :(得分:0)
所以我几乎在那里。事实证明,我所要做的就是创建一个新的DropNet客户端实例,而不是页面加载事件上的新UserLogin实例!
UserAccountManagerBLL accMan = new UserAccountManagerBLL();
UserToken = accMan.GetToken(Email);
UserSecret = accMan.GetSecret(Email);
_Client = new DropNetClient(appKey, appSecret, UserToken, UserSecret);