Appcelerator / Titanium:获取Android凭据以推送通知 [英] Appcelerator/ Titanium: Getting Android credentials to push notifications

查看:164
本文介绍了Appcelerator / Titanium:获取Android凭据以推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在Android上使用Titanium发送推送通知。但是,每当我尝试这种方法时,我都会收到后端错误,我认为这是出现无效凭据的问题。我试着按照文档,但他们似乎过时了。



这是我做的:


  1. 我访问了Google API管理器并启用了Google云消息传递。

  2. 在Credentials> OAuthConsentScreen下,我添加了一个电子邮件,产品名称和url

  3. 在Credentials> Create credentials> OAuthClientID> Web Application下,一个名字,并把一些URL放在像localhost这样的授权JavaScript起源下。 这是否需要具体说明,因为它没有在文档中提及过。
  4. 然后,Google给了我一个客户端ID和一个客户端密钥。 这是文档过期的地方


    • 客户ID的格式为:

      123456789012-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps。 googleusercontent.com

    • 客户端密码的格式为:

      XXXXXXXXXXXXXXXXXXXXXXXX


  5. 然后导航到Appcelerator仪表板中的推送通知部分,并单击 Android云消息传递。请注意,根据文档,我应该:





在GCM中输入服务器密钥API密钥字段和
GCM发件人ID字段中的GCM发件人ID


然而,这两个字段现在不同。因此,我将以下内容从Google复制到Appcelerator:


  • Google的客户端密钥到Appcelerator的服务器密钥

  • Google的客户ID到Appcelerator的服务器ID



/


  1. 然后,我使用建议的 CloudPush 模块将我的Andriod设备订阅到了一个频道(效果很好)。

    发送通知时,我的Android设备旁会显示失败一词。

    突出显示?时的完整错误消息图标如下:


    例外类型:GCM;错误代码:3103;错误消息:
    RegistrationId(s)为空或空; Catched Exception:argument can not
    be null


    我在 http://docs.appcelerator.com/arrowdb/latest/#!/guide/troubleshooting 和所有它所说的是:


    GCM客户端提供了一个空或空的注册ID。如果您使用的是Modules.CloudPush模块,则此错误为
    不常见。


    这是没有用的。



    我做错了什么?我认为我将错误的凭证放入,但不知道如何。



    我使用的文档如下所示:



    配置推送服务



    订阅推送通知



    Modules.CloudPush



    谢谢!

    更新



    在提出了很多建议后,我通过转到Create Credentials>API Key创建了另一组凭据。这给了 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 形式的新密钥。然后,我使用了:


    • Google的API Key for Appcelerator的服务器键

    • Google的项目编号的形式 123456789012 ),对于Appcelerator的服务器ID



    完全相同的错误但仍然出现。

    更新2

    Appcelerator titanium Android推送通知GCM失败?),我决定将该应用链接到Firebase。在Friebase仪表板上,我进入了Cog>项目设置>云消息传递。



    它显示了发件人ID(与项目编号完全相同)和不同的服务器密钥。



    当我使用这些证书时,发送推送通知时会出现一些稍微不同的错误:
    $ b


    例外类型:GCM;错误代码:3006;错误消息:registration_id中包含的sender_id
    与用于GCM服务器的
    寄存器的sender_id不匹配



    解决方案

    我终于设法让这个工作。基本上这些文档已经过时了。



    通过将应用链接到 Firebase
    从那里我去齿轮/设置>云消息传递


    这显示您的发件人ID(与您的项目编号相同)。对于我来说,这是一个12位数的数字。



    该页面还显示服务器密钥旧服务器密钥 。您使用哪一个似乎并不重要。



    如果您在推送通知时仍然收到以下错误:


    例外类型:GCM;错误代码:3006;错误消息:registration_id中包含的sender_id
    与用于GCM服务器的
    注册的sender_id不匹配




    <只需卸载应用程序并重新构建它即可。



    SIDENOTE:
    $ b 链接您的Firebase应用会在您的Google Console API凭证页面中自动创建多个API密钥,如 ____键(由Google服务自动创建)



    传统服务器密钥似乎与名为服务器密钥(由Google服务自动创建)一致。



    请注意,只是自己创建API密钥似乎不起作用。它必须是与Firebase关联的API密钥。


    I want to be able to send push notifications using Titanium on Android. However I get a back-end error whenever I try this, which I believe is to do with invalid credentials. I tried following the docs but they seem out of date.

    Here's what I did:

    1. I went to the Google API manager and enabled "Google Cloud Messaging".
    2. Under Credentials > OAuthConsentScreen, I added an email, product name and urls
    3. Under Credentials > Create credentials > OAuthClientID > Web Application, I gave it a name and put some URL's under Authorized JavaScript origins like localhost. Does this need to be something specific as it's not mentioned on the docs.
    4. Google then gives me a Client ID and a Client Secret. This is where the docs go out of date.

      • The Client ID is of the form: 123456789012-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com
      • The client secret is of the form: XXXXXXXXXXXXXXXXXXXXXXXX
    5. I then navigated to the push notifications section in the Appcelerator dashboard and clicked "Android Cloud Messaging". NOTE that according to the docs I should:

    Enter the server key in the GCM API Key field and the GCM sender ID in the GCM Sender ID field

    However the fields are now different on both sides. So instead I copied the following from Google to Appcelerator:

    • Google's Client Secret to Appcelerator's Server key
    • Google's Client ID to Appcelerator's Server ID

    /

    1. I then subscribed my Andriod device to a channel (which worked fine) using the suggested CloudPush module

    2. However when it comes to sending a notification, from the Appcelerator Dashboard, the word "Failure" appears next to my Android device.

    The full error message when highlighting the "?" icon is as follows:

    Exception Type: GCM; Error Code: 3103; Error Message: RegistrationId(s) is null or empty; Catched Exception: argument cannot be null

    I looked this error up on http://docs.appcelerator.com/arrowdb/latest/#!/guide/troubleshooting and all it says is:

    The GCM client provided a null or empty registration ID. This error is uncommon if you are using the Modules.CloudPush module.

    Which isn't helpful.

    What am I doing wrong? I think I am putting in the credentials wrong, but not sure how.

    The docs I was using is as follows:

    Configuring Push Services

    Subscribing to push notifications

    Modules.CloudPush

    Thanks!

    UPDATE

    After quite a few suggestions I created another set of credentials by going to "Create Credentials" > "API Key". This gave a new key of the form XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. I then used:

    • Google's API Key for Appcelerator's Server Key
    • Google's Project Number (which is of the form 123456789012), for Appcelerator's Server ID

    The exact same error still appears however.

    UPDATE 2

    After reading another Stack Overflow answer (Appcelerator titanium Android push notification GCM failure?), I decided to link the app to Firebase. On the Friebase dashboard I went to "Cog" > "Project settings" > "Cloud Messaging".

    It showed me the sender ID (which is the exactly the same as the project number) and a different server key.

    When I used these credentials, I get a slightly different error when sending the push notification:

    Exception Type: GCM; Error Code: 3006; Error Message: The sender_id contained in the registration_id does not match the sender_id used to register with the GCM servers

    解决方案

    I finally managed to get this to work. Basically the docs are heavily out of date.

    The way I managed to get it to work is by linking the app to Firebase. From there I went to "Cog/ Settings" > "Cloud Messaging".

    This shows your "Sender ID" (which is the same as your project number). For me this was a 12 digit number.

    The page also shows a Server key and a Legacy server key. It does not seem to matter which one you use.

    If you still receive the following error when pushing a notification:

    Exception Type: GCM; Error Code: 3006; Error Message: The sender_id contained in the registration_id does not match the sender_id used to register with the GCM servers

    simply uninstall the app and rebuild it.

    SIDENOTE:

    Linking your app to Firebase creates quite a few API keys automatically in your Google Console API credentials page named like "____ key (auto created by Google Service)".

    The "Legacy server key" seems to match the one called: Server key (auto created by Google Service).

    Note that just creating an API key yourself does not seem to work. It has to be the API key associated with Firebase.

    这篇关于Appcelerator / Titanium:获取Android凭据以推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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