c# - 使用访问 token 登录 Dropbox

标签 c# dropbox-api

我使用此代码(来自 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;

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

那么是否可以使用第二个链接中手动获取的访问 token 登录Dropbox?

我尝试将 token 直接传递给 dropboxServiceProvider.GetApi,但没有成功。

最佳答案

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 月才宣布的。这实际上意味着您使用的是过时的库

更多最新 API 的链接:https://www.dropbox.com/developers/core/sdks/other

更新
DropNet 的文档: http://dropnet.github.io/dropnet.html

关于c# - 使用访问 token 登录 Dropbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30128728/

相关文章:

c# - 有没有办法说 IList<xxx> 既是特定类又是接口(interface)

c# - 使用代码优先 Entity Framework 过滤多个派生类

java - 代号一 - Dropbox 2 中的 Json

swift2 - Swift 2.0 元组,许多作业

android - 在 Android 应用程序中获取 Dropbox URL

file-upload - DropboxSDK : What's the benefit of uploadFileChunk: over uploadFile: in DBRestClient?

javascript - 如何使用 dropbox.js 将文件上传到 Dropbox?

c# - 何时处置以及为什么?

c# - wcf 3.5 REST 服务使用 XML,但不使用 JSON 响应格式

c# - 使用流畅的 Nhibernate 位对属性值进行脱水时出错