[英]Load DropNet user token and secret from a database in a C# WinForms application
我想知道是否有人可以提供幫助。 我正在使用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
獲取_Client
的用戶令牌和密碼:
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;
}
}
所以我快到了。 事實證明,我要做的就是在頁面加載事件中創建一個新的DropNet客戶端實例,而不是一個新的UserLogin實例!
UserAccountManagerBLL accMan = new UserAccountManagerBLL();
UserToken = accMan.GetToken(Email);
UserSecret = accMan.GetSecret(Email);
_Client = new DropNetClient(appKey, appSecret, UserToken, UserSecret);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.