尝试通过邮递员发送下游信息时出现“错误”:“InvalidRegistration”错误

时间:2015-12-16 20:38:57

标签: android google-cloud-messaging postman

{
  "multicast_id": 7500517998248452157,
  "success": 0,
  "failure": 1,
  "canonical_ids": 0,
  "results": [
    {
      "error": "InvalidRegistration"
    }
  ]
}                    

尝试通过Google邮递员发送下游邮件时,我一次又一次地收到此错误。

我的标题是

Content-Type application/json
Authorization key=AIzaSyAGnfrtPZsepdBX5UQ6-MFuvQd3JpF1s40

我的RegistrationIntentService代码是

private static final String TAG = "RegIntentService";
private static final String[] TOPICS = {"global"};

public RegistrationIntentService() {
    super(TAG);
}

@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {
        // [START register_for_gcm]
        // Initially this call goes out to the network to retrieve the token, subsequent calls
        // are local.
        // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
        // See https://developers.google.com/cloud-messaging/android/start for details on this file.
        // [START get_token]
        InstanceID instanceID = InstanceID.getInstance(this);
        String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
        // [END get_token]
        Log.i(TAG, "GCM Registration Token: " + token);

        // TODO: Implement this method to send any registration to your app's servers.
        sendRegistrationToServer(token);

        // Subscribe to topic channels
        subscribeTopics(token);

        // You should store a boolean that indicates whether the generated token has been
        // sent to your server. If the boolean is false, send the token to your server,
        // otherwise your server should have already received the token.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
        // [END register_for_gcm]
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}

/**
 * Persist registration to third-party servers.
 *
 * Modify this method to associate the user's GCM registration token with any server-side account
 * maintained by your application.
 *
 * @param token The new token.
 */
private void sendRegistrationToServer(String token) {
    // Add custom implementation, as needed.
}

/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param token GCM token
 * @throws IOException if unable to reach the GCM PubSub service
 */
// [START subscribe_topics]
private void subscribeTopics(String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for (String topic : TOPICS) {
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
}
// [END subscribe_topics]

如何解决此问题请帮助

获取令牌的文件,如下所示

 {
  "project_info": {
"project_id": "kuwinterfest-1161",
"project_number": "413486297324",
"name": "kuwinterfest"
    },
   "client": [
     {
  "client_info": {
    "mobilesdk_app_id": "1:413486297324:android:8c55bff76e5fc52c",
    "client_id": "android:com.support.android.kuwinterfest",
    "client_type": 1,
    "android_client_info": {
      "package_name": "com.support.android.kuwinterfest"
    }
  },
  "oauth_client": [],
  "api_key": [],
  "services": {
    "analytics_service": {
      "status": 1
    },
    "cloud_messaging_service": {
      "status": 2,
      "apns_config": []
    },
    "appinvite_service": {
      "status": 1,
      "other_platform_oauth_client": []
    },
    "google_signin_service": {
      "status": 1
    },
    "ads_service": {
      "status": 1
    }
  }
}
   ],
   "client_info": [],
  "ARTIFACT_VERSION": "1"
 }

1 个答案:

答案 0 :(得分:-1)

如果这是你的实际api令牌,你应该撤销它。它应该是秘密的,或者任何人都可以使用它向您的应用发送消息。

相关问题