使用访问令牌登录 Dropbox

Signin to Dropbox using access token

我使用此代码(来自 Spring.NET Social Dropbox)通过 C# Winform 应用程序访问 Dropbox: https://github.com/spring-projects/spring-net-social-dropbox/blob/master/examples/Spring.ConsoleQuickStart/src/Spring.ConsoleQuickStart/Program.cs

DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.Full);
// Authorization without callback url
Console.Write("Getting request token...");
OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null , null).Result;
Console.WriteLine("Done");
OAuth1Parameters parameters = new OAuth1Parameters();
string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters);
Console.WriteLine("Redirect user for authorization");
Process.Start(authenticateUrl);
Console.Write("Press any key when authorization attempt has succeeded");
Console.ReadLine();
Console.Write("Getting access token...");
AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null);
OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
Console.WriteLine("Done");
IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
DropboxProfile profile = dropbox.GetUserProfileAsync().Result;

但我看到可以按照此处的说明直接获取访问令牌: https://blogs.dropbox.com/developers/2014/05/generate-an-access-token-for-your-own-account/

那么是否可以使用第二个link中手动获取的访问令牌来登录Dropbox?

我试图将令牌直接传递给 dropboxServiceProvider.GetApi,但没有成功。

从应用程序控制台生成的访问令牌是 OAuth 2 访问令牌,但您的其余代码似乎使用的是 OAuth 1。如果您使用的库支持 OAuth 2,您应该能够使用生成的访问令牌。如果没有,恐怕您必须通过 OAuth 流程获取令牌。

So is it possible to use the access token manually obtained as in the second link to sign in to Dropbox?

如果这是你的问题,答案是否定的。你不能。 Dropbox 在文档中指出。

Note that the generated access token only works for your own Dropbox account. Once you deploy your app to other users, you’ll need to use the standard OAuth authorization flow to acquire tokens for each user.

此外,关于您正在使用的库的一些信息。 spring-net-social-dropbox 最后更新于 2012 年 11 月,而 Dropbox API 是 OAuth 1.0。现在使用的 OAuth2.0 版本保管箱仅在 2013 年 7 月公布。这实质上意味着您使用的是过时的库

link 更多当前 APIs: https://www.dropbox.com/developers/core/sdks/other

更新
DropNet: http://dropnet.github.io/dropnet.html

的文档