11

我想在我的应用程序中使用保管箱。我开发了一个用于上传和下载文件的示例应用程序,它要求进行身份验证。

但我不想打开登录弹出窗口。

其他用户是否可以使用默认帐户(单个帐户)登录详细信息访问保管箱?因此,任何用户都可以直接使用 Dropbox,无需登录弹出窗口。

4

4 回答 4

7

如何手动设置访问用户访问令牌对。

     AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
     AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
     if (mDBApi == null) {
        mDBApi = new DropboxAPI<AndroidAuthSession>(session);

//  mDBApi.getSession().startAuthentication(Main.this);  //kicks off the web-based authentication
      //you'll have to use the web-based authentication UI one-time to get the ######### values
        String token_key="#########";  
        String token_seceret="#########";
        AccessTokenPair tokens=new AccessTokenPair(token_key,token_seceret);
        mDBApi.getSession().setAccessTokenPair(tokens);     
  //  boolean v=mDBApi.getSession().authenticationSuccessful(); 
    }

第一次我在带有断点的调试模式下运行应用程序时,我通过详细输入有效日志来获取令牌密钥和令牌秘密。并保存(注意)该凭证,然后我按照上面的代码手动设置它们,然后可以成功登录.

于 2013-04-02T07:47:38.783 回答
2

是的。看看他们的示例应用 DBRoulette。

于 2013-03-26T17:36:35.773 回答
0

请从以下链接名称下载项目,名称为DBRoulette

https://www.dropbox.com/developers/core

并在https://www.dropbox.com/developers中创建一个应用程序并获取 api 密钥和秘密并将其添加到DBRoulette.javaAndroidManifest.xml中......它可以工作......

于 2013-10-23T09:35:54.230 回答
0

在 onCreate() 写

AppKeyPair pair = new AppKeyPair(ACCESS_KEY, ACCESS_SECRET);
    session = new AndroidAuthSession(pair, AccessType.APP_FOLDER);
    dropbox = new DropboxAPI<AndroidAuthSession>(session);

    SharedPreferences prefs = getSharedPreferences(DROPBOX_NAME, 0);
    String key = prefs.getString(ACCESS_KEY, null);
    String secret = prefs.getString(ACCESS_SECRET, null);
    if (key != null && secret != null) {
        Log.d("key secret", key + "    " + secret);
        AccessTokenPair token = new AccessTokenPair(key, secret);
        dropbox.getSession().setAccessTokenPair(token);
    }
    if (key == null && secret == null)
            dropbox.getSession().startAuthentication(DropboxActivity.this);

并在 onResume() 中写入

if (dropbox.getSession().isLinked()) {
        try {
            loggedIn(true);
            doAction();
        } catch (IllegalStateException e) {
            Toast.makeText(this, "Error during Dropbox authentication",
            Toast.LENGTH_SHORT).show();
        }

        } else if (dropbox.getSession().authenticationSuccessful()) {
            try {
                session.finishAuthentication();
                TokenPair tokens = session.getAccessTokenPair();
                SharedPreferences prefs = getSharedPreferences(DROPBOX_NAME, 0);
                Editor editor = prefs.edit();
                editor.putString(ACCESS_KEY, tokens.key);
                editor.putString(ACCESS_SECRET, tokens.secret);
                editor.commit();

                loggedIn(true);
                doAction();

            } catch (IllegalStateException e) {
                Toast.makeText(this, "Error during Dropbox authentication",
                        Toast.LENGTH_SHORT).show();
            }

        }

对我来说效果很好

于 2015-02-06T13:17:30.773 回答