Dropbox的Andr​​oid的API需要重新认证 [英] Android dropbox api needs re-authentication

查看:129
本文介绍了Dropbox的Andr​​oid的API需要重新认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用Dropbox的API来保留一些文件,它的确定。认证后我关闭应用程序,然后重新启动应用程序。它需要重新验证每一个我打开application.I时间希望应用程序还记得我的会话。

In my application, i use dropbox api to keep some files, it's ok. After authentication i close the app and re-launch app. It needs re-authentication each time i opened the application.I want the application to remember my session.

推荐答案

Dropbox的教程建议存储认证令牌的共享preferences,所以你可以在以后恢复它。

Dropbox tutorial suggest storing the authentication token as SharedPreferences, so you could restore it later.

您可以看到位于 \\ Dropbox的,Android的SDK-1.6 \\例子\\ DBRoulette的Dropbox SDK

在活动的的onCreate()方法检查是否preference存储,如果它是那么instean调用验证窗口使用会话。 setOAuth2AccessToken(RESTORED_TOKEN);

In the activity's onCreate() method check if preference is stored and if it is then instean of calling authentication window use session.setOAuth2AccessToken(RESTORED_TOKEN);

样code要做到这一点:

Sample code to do this:

public void onCreate() {
    AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
    mDBApi = new DropboxAPI<AndroidAuthSession>(session);

    String token = getTokenFromPreferences();
    if (token != null) {
        session.setOAuth2AccessToken(token);
    } else {
        mDBApi.getSession().startOAuth2Authentication(MyActivity.this);
    }
}

这篇关于Dropbox的Andr​​oid的API需要重新认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆