我想在我的应用程序中使用dropbox。我开发了一个用于上传和下载文件的示例应用程序,并要求进行身份验证。
但我不想打开登录弹出窗口。
是否可以使用默认帐户(单个帐户)登录详细信息访问其他用户的Dropbox? 因此,任何用户都可以直接使用dropbox而无需登录弹出窗口。
答案 0 :(得分: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();
}
我第一次在调试模式下使用断点运行应用程序我通过输入有效的详细记录来获取令牌密钥和令牌秘密。并保存(注明)该凭证,然后我按照上面的代码手动设置它们然后可以登录成功。
答案 1 :(得分:2)
是。看看他们的示例应用程序DBRoulette。
答案 2 :(得分:0)
请从以下链接名称下载项目 DBRoulette
在https://www.dropbox.com/developers中创建一个应用并获取api密钥并保密,并将其添加到 DBRoulette.java 和 AndroidManifest.xml 中...它有效..
答案 3 :(得分: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();
}
}
它对我来说很好