[英]Store user token from Dropbox using DropNet
一旦我的應用程序已被Dropbox授權,我將嘗試存儲用戶令牌,以便當我打開其他表單(具有拖放功能)時,用戶無需再次授權應用程序,並且能夠執行向Dropbox的上傳功能。
我使用DropNet授權Dropbox的課程是:
我已經聲明了兩個屬性; public string UserToken { get; set; }
public string UserToken { get; set; }
和public string UserSecret { get; set; }
public string UserSecret { get; set; }
string appKey = "APP_KEY";
string appSecret = "APP_SECRET";
public bool LinkDrpbox()
{
bool dropboxLink = false;
Authenticate(
url =>
{
var proc = Process.Start("iexplore.exe", url);
proc.WaitForExit();
Authenticated(
() =>
{
dropboxLink = true;
},
exc => ShowException(exc));
},
ex => dropboxLink = false);
if (dropboxLink)
{
return true;
}
else
{
return false;
}
}
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;
}
}
public bool IsAuthenticated
{
get
{
return UserToken != null &&
UserSecret != null;
}
}
public void Authenticate(Action<string> success, Action<Exception> failure)
{
Client.GetTokenAsync(userLogin =>
{
var url = Client.BuildAuthorizeUrl(userLogin);
if (success != null) success(url);
}, error =>
{
if (failure != null) failure(error);
});
}
public void Authenticated(Action success, Action<Exception> failure)
{
Client.GetAccessTokenAsync((accessToken) =>
{
UserToken = accessToken.Token;
UserSecret = accessToken.Secret;
if (success != null) success();
},
(error) =>
{
if (failure != null) failure(error);
});
}
private void ShowException(Exception ex)
{
string error = ex.ToString();
}
}
我可以授權我的應用程序,但不確定如何保存訪問令牌。 我想在app.config
文件中,但不確定。
任何幫助,將不勝感激!
這更多是.net問題,而不是DropNet特定問題。
看看這個答案https://stackoverflow.com/a/3032538/75946我不同意使用注冊表,但是其他兩個都很好。
您只需要在啟動應用程序並將其設置在DropNetClient實例上時從存儲位置加載它即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.