0

I'm using Google Cloud Messaging api to implement an Android client. To get a token, I do:

   InstanceID ex = InstanceID.getInstance(this.getApplicationContext());
   String regId = ex.getToken(senderId, "GCM", null);

And regId always contains a token, despite of I put on senderId. If I set senderId with "123", InstanceID returns a token! (But the, I don't receive notifications with this token). Why I always get a token? I expect an exception, or a null value maybe...

4

1 回答 1

0

您可能总是会获得一个令牌,但您将无法使用它来建立完整的 gcm 生命周期,因为instanceId它与您的应用服务器的senderId.

来自谷歌文档

使用该getToken方法证明 InstanceID 的所有权,并允许服务器访问与应用程序关联的数据或服务。该方法遵循 OAuth2 的模式,并且需要一个授权实体和范围。authorizedEntity 可以是项目 ID 或另一个 InstanceID,它确定有权使用生成的令牌的服务。范围确定令牌允许访问的特定服务或数据。

要了解更多生命周期,请参阅文档

于 2016-03-09T16:32:03.863 回答