谷歌云信息登记AUTHENTICATION_FAILED信息、谷歌云、AUTHENTICATION_FAILED

2023-09-12 10:16:56 作者:丢了心的自己

我想尝试谷歌云消息(GCM)的服务,我面对一开始的一个问题。

I want to try Google Cloud Messaging (GCM) service, and I am faced with a problem at the beginning.

我得到一个错误 AUTHENTICATION_FAILED ,同时试图将设备注册到GCM。 我搜索和所有我发现是不正确的密码的变化。我的密码是正确的,我只用一个账号。

I get an error AUTHENTICATION_FAILED while trying to register a device to GCM. I searched and all I found were variations of the incorrect password. My password is correct and I am using just one account.

有两种实现在Android GCM客户端的方式:

There are two ways to implement GCM client on Android:

在额外的罐子GCM库,现在去precated。 在谷歌播放服务API

我开始课程的第二,得到了这个问题。

I started with the second of course and got this issue.

我想这个问题是在我的手机,但后来决定尝试第一种方式,它的工作! 然而,pcated德$ P $,并且需要额外的罐子,它似乎并不像正确的方式。

I thought the problem is in my phone, but then decided to try the first way, which worked! However, it is deprecated and requires an additional jar, which doesn't seem like the right way.

在一个试图了解的原因错误,我反编译谷歌播放服务罐子和GCM库进行了比较。

In an attempt to understand the reasons for the error, I decompiled Google Play Services jar and compared it with GCM library.

原来,他们都有类似的方法,是这样的:

It turns out they both have a similar method, something like:

void register(Context context, String senderIds) {
    Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
    intent.setPackage("com.google.android.gms"); // this one row are different
    setPackageNameExtra(context, intent);
    intent.putExtra("sender", senderIds);
    context.startService(intent);
}

在一排的区别:

在GCM库是 com.google.android.gsf ,其中 GSF 是谷歌服务框架(我猜),和它的作品!

In GCM library it is com.google.android.gsf, where gsf is Google Services Framework (I guess), and it works!

在谷歌播放服务API罐子是 com.google.android.gms ,而且它不工作(AUTHENTICATION_FAILED错误)。

In Google Play Services API jar it is com.google.android.gms, And it does not work (AUTHENTICATION_FAILED error).

然后在GCM库我改为GSF,以克和运行。而我得到了同样的错误AUTHENTICATION_FAILED!如果我进入另一个包,那么它是不工作。

Then in GCM library I replaced "gsf" to "gms" and run. And I got the same AUTHENTICATION_FAILED error! If I enter another package, then it is not working.

什么是我需要做的,使其工作?我应该设置一些在手机?或者是在谷歌播放业务中的错误?有人遇到过这样的问题吗?

What do I need to do to make it work? Should I set up something in the phone? Or is it a bug in Google Play Services? Have someone encountered such a problem?

在此先感谢!

推荐答案

我碰到了同样的问题,它似乎并不像谷歌是在任何急于修复它。

I ran into the same problem, and it doesn't seem like google is in any hurry to fix it.

我不想去precated客户端辅助gcm.jar添加到我的应用程序,所以我codeD最小的解决方案,在我的Andr​​oid 2.3.6的Nexus One手机,工作失败登记在上述

I didn't want to add the deprecated client helper gcm.jar to my app, so I coded a minimal solution that works on my Android 2.3.6 Nexus One phone that fails registration as in the question above

            try {
                gcm = GoogleCloudMessaging.getInstance(context);
                regID = gcm.register(SENDER_ID);
                storeRegistrationId(regID);
                msg = "Device registered, registration ID=" + regID;

                sendRegistrationIdToBackend();
            } catch (IOException ex) {
                msg = "Exception registering for GCM :" + ex.getMessage();
                // If there is an error, don't just keep trying to register.
                oldSchoolRegister();
            }

在AUTHENTICATION_FAILED触发IOException异常在code以上

The AUTHENTICATION_FAILED triggers the IOException in the code above

private void oldSchoolRegister() {
    Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
    intent.setPackage("com.google.android.gsf");
    setRegCallbackIntent(context, intent);
    intent.putExtra("sender", SENDER_ID);
    context.startService(intent);
}

private static synchronized void setRegCallbackIntent(Context context, Intent intent) {
    regCallback = PendingIntent.getBroadcast(context, 0, new Intent(), 0);
    intent.putExtra("app", regCallback);
}

public static synchronized void cancelRegCallbackIntent() {
    if (regCallback != null) {
        regCallback.cancel();
        regCallback = null;
    }
}

我添加了上述code到我的应用程序。他们简化从客户端辅助gcm.jar方法(这样你就不会需要将jar添加到您的应用程序)

I added the above code to my app. They are simplified methods from the Client Helper gcm.jar (so you don't need to add the jar to your app)

protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();

    if (extras != null && !extras.isEmpty()) {  // has effect of unparcelling Bundle
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        String messageType = gcm.getMessageType(intent);

        if (messageType != null) {
            if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                showMessage(extras.getString("message")); // call your code
                Logger.d(TAG, "Received message: " + message.alert + ": " + message.url);
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
                Logger.e(TAG, "Send error: " + extras.toString());
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
                Logger.e(TAG, "Deleted messages on server: " + extras.toString());
            }
        } else {
            String regID = extras.getString("registration_id");
            if (regID != null && !regID.isEmpty()) {
                doRegistration(regID); // send to your server etc.
                GCMSetup.storeRegistrationId(regID);
                GCMSetup.cancelRegCallbackIntent();
            }
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GCMBroadcastReceiver.completeWakefulIntent(intent);
}

这code是在故意服务,并有几行存储的ID从GCM获得。正如你所看到的只有约20额外的$ C $的行C相比,基本实现,并没有额外的依赖!你只需要更新您的Andr​​oidManifest.xml,以确保您能收到报名意向。

This code is in the intent service, and has a few lines to store the ID received from GCM. As you can see only about 20 extra lines of code compared to a basic implementation, and no additional dependencies! You only need to update your AndroidManifest.xml to make sure you can receive the REGISTRATION intent.

    <receiver android:name="com.camiolog.android.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
            <category android:name="com.camiolog.android"/>
        </intent-filter>
    </receiver>

我希望这有助于谷歌之前,得到了他们的共同行动!

I hope this helps until google gets their act together!

 
精彩推荐
图片推荐