我可以通过编程方式向 Dropbox API 进行身份验证吗?

Can I authenticate to Dropbox API programmatically?

我正在 Android 上使用 Dropbox API 开发 android 应用程序。 API 有一个 link activity 到 link 一个应用程序帐户。

我有应用密钥和应用密码以及 Dropbox 帐户和密码,我需要以编程方式将这些信息放入代码中。

我不想要的是这个login/linkactivity,假设我有一个Dropbox帐户和密码,我想link/authenticate 以编程方式使用此特定帐户,而不要求用户 link 或登录或输入任何帐户或密码。

我可以这样做吗?

嗯,我发现 dropbox 实际上提供了我想做的事情。

现在 Dropbox 将允许您生成 public 访问令牌并在您的代码中使用它

所以是的,有一种方法允许永久访问保管箱 API。我们需要从应用程序设置(保管箱控制台)生成访问令牌并使用它。这是保管箱所说的:

By generating an access token, you will be able to make API calls for your own account without going through the authorization flow. To obtain access tokens for other users, use the standard OAuth flow.

中码字:

AndroidAuthSession session = buildSession();
mApi = new DropboxAPI<AndroidAuthSession>(session);

    private AndroidAuthSession buildSession() {
        AppKeyPair appKeyPair = new AppKeyPair(APP_KEY, APP_SECRET);
        AndroidAuthSession session = new AndroidAuthSession(appKeyPair, ACCESS_TOKEN);
        // I guess then you just have to instantiate a DropboxAPI object and you're good to go without the startAuthentication()... endAuthentication() etc.
        return session;
    }

现在我们开始使用 mApi 做任何你想做的事