- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 JellyBean 设备上。
我正在关注 this请求 oauth2 token ,例如
AccountManager am = AccountManager.get(getActivity());
am.invalidateAuthToken(MY_AUTH_TOKEN_TYPE, null);
am.getAuthToken(aGoogleAccount, MY_AUTH_TOKEN_TYPE, null, this,
new OnTokenAcquired(), new Handler(new OnError()));
然后按照后面的代码示例进行检查:
private class OnTokenAcquired implements AccountManagerCallback<Bundle> {
@Override
public void run(AccountManagerFuture<Bundle> result) {
Bundle bundle = result.getResult();
...
Intent launch = (Intent) bundle.get(AccountManager.KEY_INTENT);
if (launch != null) {
startActivityForResult(launch, 0);
return;
}
}
}
我从来没有得到 KEY_INTENT。我了解以下内容:
There may be many reasons for the authenticator to return an Intent. It may be the first time the user has logged in to this account. Perhaps the user's account has expired and they need to log in again, or perhaps their stored credentials are incorrect. Maybe the account requires two-factor authentication or it needs to activate the camera to do a retina scan. It doesn't really matter what the reason is. If you want a valid token, you're going to have to fire off the Intent to get it.
但是,getAuthToken
始终会导致权限屏幕或登录屏幕出现在代码命中 run
方法之前,此时 token 有效。我试过:
run
之前请求帐户登录,因此在 run
中始终有 token 。run
之前再次请求帐户登录,因此在 run
中始终有 token 。没有能力尝试视网膜扫描,所以有些不知所措。
EDIT 1 我遇到的问题是在某些情况下我会得到一个 KEY_INTENT
所以我宁愿现在而不是什么时候测试这个代码路径它在外地。
提前致谢。
彼得。
最佳答案
有机会在项目中做类似的事情。这与您的代码不完全相同,我仍然说回调文档有太多“可能”无法确定它应该如何工作,但如果您使用 this method为 notifyAuthFailure
传递 false
,如果您更改密码或启用 2FA,您将获得重新登录屏幕的 Intent 。这是针对 ClientLogin 的,但对于 OAuth 2(虽然未测试)应该类似地工作。像这样的东西:
// using Calendar ClientLogin for simplicity
Bundle authResult = am.getAuthToken(account, "cl", false, null, null).getResult();
if (authResult.containsKey(AccountManager.KEY_INTENT)) {
Intent authIntent = authResult.getParcelable(AccountManager.KEY_INTENT);
// start activity or show notification
}
关于android - 永远不要从 getAuthToken 请求中获取 AccountManager.KEY_INTENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12970481/
我正在使用 getAuthToken() 获取 token ,然后登录 Google App Engine 应用程序。 它曾经有效,直到今天,我不知道为什么 getAuthToken() 返回 nul
我有几个关于 AccountManager 类的 getAuthToken() 方法的问题。 “authTokenType”可以取什么值?到目前为止,我只看到它取值“啊”。 getAuthToken(
我正在尝试获取 Google 帐户的授权 token ,因为我正在使用以下代码: AccountManager acoountManager = AccountManager.get( getCon
我正在使用 AbstractAccountAuthenticator 的自定义实现,并且我已经按照文档实现了 getAuthToken。我一直在关注本教程:http://blog.udinic.com
我正在 Android 中制作一个简单的 REST 客户端:我创建了一个负责 REST 调用的服务,但它需要用户名和密码才能运行。用户名和密码存储在常规帐户注册表中,所以我想做的是在服务中检索用户名和
一旦用户验证我的应用程序以查看和管理邮件,我的代码就可以工作。 或者看起来像这样: 然而,对于第一次(对于第一个请求),谷歌的对话框出现(上方)并要求用户进行身份验证,然后即使用户选择“确定”(即使“
我的应用程序使用客户管理器共享身份验证 token ,它在 4.0 早期运行良好。但是当我在我的 Nexus S (4.0.3) 中试用该应用程序时,每次我调用 getAuthToken 方法时都会发
在使用 Android 的 AccountManager 获取 Google 帐户的授权 token 时,我遇到了一个奇怪的行为。 应用启动时,第一次调用 getAuthToken 会返回一个包,其中
我通过扩展 AbstractAccountAuthenticator 创建了自己的 Android 帐户 validator 并实现 addAccount()和 getAuthToken() .其中的
当我调用 AccountManager.get(this).getAuthTokenByFeatures(Constants.ACCOUNT_TYPE, Constants.AUTHTOKEN_TYP
我在 Android 中有一个应用程序,我正在尝试使用 AccountManager 获取 AuthToken 并使用 Facebook 或 Twitter 进行操作。所以我得到了这个: Accoun
我的代码: Account[] accts = mgr.getAccountsByType("com.google"); Account acct = accts[0]; System.out.pri
我的印象是在使用 chrome.identity.getAuthToken 和 gapi.auth.authorize({immediate: true...}); token 将在后台刷新。 但它显
我已经扩展了 AbstractAccountAuthenticator 并覆盖了 getAuthToken。一切都适用于我的 getAuthToken,除非缓存的 authtoken 有效,在这种情况
在 JellyBean 设备上。 我正在关注 this请求 oauth2 token ,例如 AccountManager am = AccountManager.get(getActivity())
使用 Eclipse 创建了一个测试应用程序,以从我设备上的一个 Google 电子邮件帐户获取 authToken。 执行此操作会提示我允许访问对话框,我在其中按允许访问: accountManag
我正在使用 Chrome Identity API,在我的 Chrome 扩展程序上为用户提供 Google 身份验证。 我跟着谷歌的官方教程:link Chrome Identity API 我为
ChromeOS 版本 63.0.3239.140(官方版本)(64 位) 你好, 我在使用 https://developer.chrome.com/apps/identity#method-get
我为我想在具有不同签名的其他应用程序中使用的 Web 服务构建了一个 AccountAuthenticator。我想立即显示全屏访问请求对话框(这个:http://i.imgur.com/gcndGZ
我在一个 Multi-Tenancy 团队应用程序中工作,并想使用 SSO 向机器人添加一个选项卡。在我的开发环境中,这一切正常,我可以毫无问题地登录。当我将其部署到 QA 环境时,出现以下错误 AU
我是一名优秀的程序员,十分优秀!