谷歌播放服务:TokenActivity要求身份验证时,会出现空 [英] Google Play Services: TokenActivity appears empty when asking for auth

查看:409
本文介绍了谷歌播放服务:TokenActivity要求身份验证时,会出现空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用谷歌驱动器作为后端的应用程序。我已经通过了DrEdit例如运行,我在与授权的问题。我得到的地步,我收到了 UserRecoverableAuthException ,并用它来发布,用户需要做的事情的通知。问题是,似乎没有什么,当我点击该通知的情况发生。

I'm working on an app that uses Google Drive as a backend. I've run through the DrEdit example and I'm having issues with the authorization. I get to the point where I get a UserRecoverableAuthException and use it to post a notification that the user has to do something. The problem is that nothing seems to happen when I click that notification.

我说什么出现的情况发生,因为它看起来像谷歌游戏推出来处理它,它只是不可见。如果我打的应用程序切换按钮,我可以看到谷歌Play服务的瓷砖半透明的背景,但用户不会看到屏幕AUTH

I say nothing 'appears' to happen because it looks like Google Play is launching to handle it, it's just invisible. If I hit the app switch button I can see the Google Play services tile with a translucent background, but the user never sees the auth screen.

有我丢失的东西?我在访问驱动器配置的API控制台项目,并为我释放键和发展建立补充说。

Is there something I'm missing? I have a project in that APIs console configured with drive access and the keys for both my release and develop builds added.

这里的code我使用的通知。它是pretty多究竟有什么DrEdit样品中(其中也有同样的问题)。

Here's the code I'm using for the notification. It's pretty much exactly what's in the DrEdit sample (which also has the same problem).

try {
    GoogleAccountCredential credential =
            GoogleAccountCredential.usingOAuth2(mContext, DriveScopes.DRIVE_FILE);
    credential.setSelectedAccountName(mAccount.name);
    // Trying to get a token right away to see if we are authorized
    credential.getToken();
    mService = new Drive.Builder(AndroidHttp.newCompatibleTransport(),
            new GsonFactory(), credential).build();
} catch (UserRecoverableAuthException e) {
    Log.e("Failed to get token");
    // If the exception is User Recoverable, we display a notification that will trigger the
    // intent to fix the issue.
    Log.e("Notifying with intent: " + e.getIntent().toString());
    NotificationManager notificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Intent authorizationIntent = e.getIntent();
    authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
            Intent.FLAG_FROM_BACKGROUND);
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, 
            authorizationIntent, 0);
    Notification notification = new Notification.Builder(mContext)
            .setSmallIcon(android.R.drawable.ic_dialog_alert)
            .setTicker("Permission requested")
            .setContentTitle("Permission requested")
            .setContentText("for account " + mAccount.name)
            .setContentIntent(pendingIntent).setAutoCancel(true).build();
    notificationManager.notify(0, notification);
} catch (Exception e) {
        e.printStackTrace();
}

编辑:

我只是想澄清的是,我有一个谷歌API的项目设置与访问该驱动器API(最初是驱动器的SDK,但我固定的)和我为我的应用程序获取与调试键密钥工具-exportcert -alias androiddebugkey -keystore〜/ .android / debug.keystore -list -v 。仍然没有运气。

推荐答案

我终于想通这一个。它看起来像文档和示例都有点过时了,因为仅仅有 DriveScopes.DRIVE_FILE 的范围是不够的,它需要prepended与的OAuth:

I've finally figured this one out. It looks like the docs and sample are a bit outdated, because just having DriveScopes.DRIVE_FILE for the scope isn't enough, it needs to be prepended with "oauth:".

下面是我的code:

try {
    // Trying to get a token right away to see if we are authorized
    GoogleAuthUtil.getTokenWithNotification(mContext, mAccount.name, 
            "oauth2:" + DriveScopes.DRIVE_FILE, null, mAuthority, mSyncBundle);
} catch (UserRecoverableNotifiedException e) {
    Log.e("Failed to get token but notified user");
    return null;
} catch (Exception e) {
    Log.e("Failed to get token", e);
    return null;
}

try {
    GoogleAccountCredential credential =
        GoogleAccountCredential.usingOAuth2(mContext, DriveScopes.DRIVE_FILE);
    credential.setSelectedAccountName(mAccount.name);
    ...

注意:我也决定改用 GoogleAuthUtil.getTokenWithNotification 来让库处理通知我,然后重新启动同步适配器时,它的完整的。

Note: I also decided to switch to GoogleAuthUtil.getTokenWithNotification to let the library handle the notification for me and restart the sync adapter when it's complete.

这篇关于谷歌播放服务:TokenActivity要求身份验证时,会出现空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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