在android应用程序中集成Dropbox,但没有登录弹出窗口
我想在我的应用程序中使用dropbox。我开发了一个用于上传和下载文件的示例应用程序,它要求进行身份验证 但我不想打开登录弹出窗口 其他用户是否可以使用默认帐户(单个帐户)登录详细信息访问dropbox?在android应用程序中集成Dropbox,但没有登录弹出窗口,android,dropbox,dropbox-api,Android,Dropbox,Dropbox Api,我想在我的应用程序中使用dropbox。我开发了一个用于上传和下载文件的示例应用程序,它要求进行身份验证 但我不想打开登录弹出窗口 其他用户是否可以使用默认帐户(单个帐户)登录详细信息访问dropbox? 因此,任何用户都可以直接使用dropbox,而无需登录弹出窗口。是。看看他们的示例应用程序dbroulete。如何手动设置访问用户访问令牌对 AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET); AndroidA
因此,任何用户都可以直接使用dropbox,而无需登录弹出窗口。是。看看他们的示例应用程序dbroulete。如何手动设置访问用户访问令牌对
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();
}
AppKeyPair appKeys=新的AppKeyPair(APP\u KEY,APP\u SECRET);
AndroidAuthSession会话=新的AndroidAuthSession(appKeys,访问类型);
如果(mDBApi==null){
mDBApi=新的DropboxAPI(会话);
//mDBApi.getSession().startAuthentication(Main.this);//启动基于web的身份验证
//您必须一次性使用基于web的身份验证UI来获取值
字符串标记_键=“##########”;
字符串标记_seceret=“##########”;
AccessTokenPair令牌=新的AccessTokenPair(令牌密钥,令牌密钥);
mDBApi.getSession().setAccessTokenPair(令牌);
//布尔值v=mDBApi.getSession().authenticationSuccessful();
}
第一次在调试模式下使用断点运行应用程序时,我通过详细输入有效日志获得的令牌密钥和令牌密钥。并保存(注意)该凭据,然后我将其手动设置为上述代码,然后可以成功登录。请从以下链接名称下载项目,名称为dbroulete 并在中创建一个应用程序,获取api密钥和密码,并将其添加到dbroulete.java和AndroidManifest.xml…它在onCreate()write中起作用
这对我来说很好你能提供更多关于你想做什么的信息吗?为什么只有一个dropbox帐户?我怀疑DB会让你这么做。或多或少有点重复:我想使用dropbox作为服务器,这样任何用户都可以上传和下载文件到单个帐户,而无需与dropbox登录交互。感谢所有回复。我已通过手动设置用户访问令牌对来解决此问题。在没有登录的情况下,其他用户也可以正常工作。在不启动dropbox身份验证屏幕的情况下,如何手动获取token_key和token_secret?您必须启动身份验证屏幕,但只需启动一次。然后关闭它并手动设置令牌密钥对,如上所示。但是否可以在源代码中硬编码凭据,以便身份验证屏幕不会显示一次。。如果我想向100名用户展示演示,他们需要为该演示键入user/pass,我想避免这种情况..:S@DhiliphSoundher,登录后,您可以获取密钥和令牌,但需要在调试模式下运行应用程序,并将断点放在希望获取变量的位置。
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);
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();
}
}