Glassware auth:android.accounts.OperationCanceledException“不允许共享凭据:取消.”

前端之家收集整理的这篇文章主要介绍了Glassware auth:android.accounts.OperationCanceledException“不允许共享凭据:取消.”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们正在尝试实施GDK玻璃器皿验证;已将我们的测试版APK上传至Google Glass团队,并成功实施了我们的MyGlass登录页面.我们现在尝试通过此处列出的步骤访问令牌: https://developers.google.com/glass/develop/gdk/authentication#retrieving_accounts_on_glass

但是最后一步,String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);导致以下异常:

09-22 18:07:24.126: I/AccountManagerService(519): Sharing credentials is not allowed: canceling.
09-22 18:07:24.313: W/System.err(5822): android.accounts.OperationCanceledException
09-22 18:07:24.313: W/System.err(5822):     at android.accounts.AccountManager$AmsTask.internalGetResult(AccountManager.java:1503)
09-22 18:07:24.313: W/System.err(5822):     at android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1531)
09-22 18:07:24.313: W/System.err(5822):     at android.accounts.AccountManager$AmsTask.getResult(AccountManager.java:1452)
09-22 18:07:24.313: W/System.err(5822):     at com.mycom.app.MainActivity$5.run(MainActivity.java:234)
09-22 18:07:24.313: W/System.err(5822):     at android.accounts.AccountManager$11.run(AccountManager.java:1427)
09-22 18:07:24.313: W/System.err(5822):     at android.os.Handler.handleCallback(Handler.java:733)
09-22 18:07:24.313: W/System.err(5822):     at android.os.Handler.dispatchMessage(Handler.java:95)
09-22 18:07:24.313: W/System.err(5822):     at android.os.Looper.loop(Looper.java:149)
09-22 18:07:24.313: W/System.err(5822):     at android.app.ActivityThread.main(ActivityThread.java:5061)
09-22 18:07:24.313: W/System.err(5822):     at java.lang.reflect.Method.invokeNative(Native Method)
09-22 18:07:24.313: W/System.err(5822):     at java.lang.reflect.Method.invoke(Method.java:515)
09-22 18:07:24.313: W/System.err(5822):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-22 18:07:24.313: W/System.err(5822):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
09-22 18:07:24.313: W/System.err(5822):     at dalvik.system.NativeStart.main(Native Method)

我们试图通过Mirror API推送的请求就是这样形成的(并返回一个OK状态代码):

POST https://www.googleapis.com/mirror/v1/accounts/google_user_token/com.ourcom.app.session/ourapp_username

BODY 
{"authTokens":[{"type":"com.ourcom.app.session","authToken":"****************"}]}

HEADERS
{"Authorization":"Bearer ya29.iAAf********","Content-Type":"application/json;charset=utf-8"}

这是我们当地的玻璃代码

AccountManager accountManager = AccountManager.get(this);
// Use your Glassware's account type.
Account[] accounts = accountManager.getAccountsByType("com.ourcom.app.session");

// Your auth token type.
final String AUTH_TOKEN_TYPE = "com.ourcom.app.session";

if (accounts.length > 0) {

    accountManager.getAuthToken(accounts[0],AUTH_TOKEN_TYPE,null,this,new AccountManagerCallback<Bundle>() {

        @Override
        public void run(AccountManagerFuture<Bundle> future) {
            try {
                String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);

                //do something with token

                });


            } catch (Exception e) {
                //handle exception
                //this is where we get our OperationCancelledException
                e.printStackTrace();

            }
        }


    },null);
} else {
    //handle not authed state
}

什么可能导致这种错误? Mirror POST URL末尾的用户名是否应该与特定内容匹配,或者我们可以自由使用我们自己的东西吗?

解决方法

要检查几件事:

>您的应用程序的软件包名称是否与提交Glassware时提供的软件包名称完全匹配?>您是否通过MyGlass至少安装了一次提交的APK,而不是总是用adb侧载它?确保卸载APK,然后通过在MyGlass中打开它来安装它,以便正确设置权限;从那时起,您可以通过将ad替换为adb来继续开发.

猜你在找的Android相关文章