我试图在我的应用程序被Dropbox授权后存储一个用户令牌,这样当我打开一个不同的表单(它将具有拖放功能)时,用户将不必再次授权该应用程序,并且能够对Dropbox执行上传功能。
我使用DropNet授权Dropbox的课程是:
我已经声明了两个属性:public string UserToken { 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文件中推测,但不确定。
任何帮助都将不胜感激!
发布于 2015-05-14 14:11:34
这更像是一个.net问题,而不是一个DropNet特定的问题。
看看这个答案,https://stackoverflow.com/a/3032538/75946,我不同意使用注册表,但其他2是好的。
当您启动应用程序并在您的DropNetClient实例上设置它时,您只需要从存储它的地方加载它。
https://stackoverflow.com/questions/30238297
复制相似问题