GCM(Google Cloud Messaging)的服务器端错误“ invalidRegistration”

碧玉

当我运行GCM客户端代码时,出现“ invalidRegistration”错误。我检查了引用页面。但是仍然无法成功1. JSON文件提供的API密钥和服务器API密钥是在配置过程不同时获得的,但是对于我自己来说,我都获得了InvalidRegistarion。 MainActivity扩展了AppCompatActivity {

private TextView mTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTextView = (TextView) findViewById(R.id.textView);

    new GCMRequest().execute();
}


private class GCMRequest extends AsyncTask<Void, Void, String> {

    @Override
    protected String doInBackground(Void... voids) {

        final String API_KEY = "AIzaSyCNPlrqXeZ8IlNYsQGlseHhHPCfgcR5V7c"; // An API key saved on the app server that gives the app server authorized access to Google services
        final String CLIENT_REG_ID = "821083769456"; //An ID issued by the GCM connection servers to the client app that allows it to receive messages
        final String postData = "{ \"registration_ids\": [ \"" + CLIENT_REG_ID + "\" ], " +
                "\"delay_while_idle\": true, " +
                "\"data\": {\"tickerText\":\"My Ticket\", " +
                "\"contentTitle\":\"My Title\", " +
                "\"message\": \"Test GCM message from GCMServer-Android\"}}";

        try {
            URL url = new URL("https://android.googleapis.com/gcm/send");
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setDoInput(true);
            urlConnection.setDoOutput(true);
            urlConnection.setRequestMethod("POST");
            urlConnection.setRequestProperty("Content-Type", "application/json");
            urlConnection.setRequestProperty("Authorization", "key=" + API_KEY);

            OutputStream outputStream = new BufferedOutputStream(urlConnection.getOutputStream());
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "utf-8"));
            writer.write(postData);
            writer.flush();
            writer.close();
            outputStream.close();

            int responseCode = urlConnection.getResponseCode();
             InputStream inputStream;
            if (responseCode < HttpURLConnection.HTTP_BAD_REQUEST) {
                inputStream = urlConnection.getInputStream();
            } else {
                inputStream = urlConnection.getErrorStream();
            }
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String temp, response = "";
            while ((temp = bufferedReader.readLine()) != null) {
                response += temp;
            }
            return response;
        } catch (IOException e) {
            e.printStackTrace();
            return e.toString();
        }
    }

    @Override
    protected void onPostExecute(String message) {
        super.onPostExecute(message);

        if (mTextView != null) {
            try {
                JSONObject jsonObject = new JSONObject(message);
                mTextView.setText(jsonObject.toString(5));
            } catch (JSONException e) {
                e.printStackTrace();
                mTextView.setText(e.toString());
            }
        }
    }
}

}`

输出为:

{
multicast_id:XXXX,
success:0,
failure:1,
results:
{
error:InvalidRegistration
}

提前致谢。

特亚姆

Cloud Messaging的建议-注册客户端应用程序,如果使用指数退避注册失败,则客户端应用程序应重试注册操作。

除此之外,还提到您应该从服务器启动令牌刷新,以保护客户端应用程序和应用程序服务器免受潜在恶意重用注册令牌的侵害。当从服务器端启动GCM注册令牌刷新时,客户端应用必须通过GCM注册客户端/服务器握手来处理tokenRefreshed消息。

希望给定的参考对您有所帮助。:)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Google Cloud Messaging / GCM

来自分类Dev

使用GCM在应用上发送通知,返回InvalidRegistration错误

来自分类Dev

将Google Cloud Messaging集成到Android App-GCM连接服务器

来自分类Dev

服务器端GCM返回错误400

来自分类Dev

Firebase Cloud Messaging和C#服务器端代码

来自分类Dev

Google Cloud Messaging-CCS(XMPP)与HTTP服务器

来自分类Dev

服务器端Google授权

来自分类Dev

服务器端Google授权

来自分类Dev

GCM服务器端PHP-未经授权的401错误

来自分类Dev

与Firebase相关的Google Play服务更新后,Android Google Cloud Messaging(GCM)令牌生成崩溃

来自分类Dev

如何使用PHP设置新的Google Cloud Messaging API服务器实现和托管?

来自分类Dev

服务器端Google Analytics(分析)实验

来自分类Dev

statsd / graphite与Google Analytics(分析)服务器端

来自分类Dev

如何验证Google身份服务器端

来自分类Dev

Google+服务器端令牌验证

来自分类Dev

如何验证Google身份服务器端

来自分类Dev

Google Analytics 服务器端 - 隐藏跟踪 ID

来自分类Dev

适用于Android和推送通知的Google Cloud Messaging GCM

来自分类Dev

接收到UWP Windows 10应用程序的Google Cloud Messaging(GCM)推送通知

来自分类Dev

Send push notification using GCM to multiple topics at a time in ios #ios # google-cloud-messaging

来自分类Dev

在Android上具有本地设备组的Google Cloud Messaging(GCM)给出了HTTP错误代码401

来自分类Dev

在Android上具有本地设备组的Google Cloud Messaging(GCM)给出了HTTP错误代码401

来自分类Dev

Google Android Gcm服务器

来自分类Dev

发送服务器端 Google Analytics 数据而不发送服务器位置

来自分类Dev

如何使用InstanceID从服务器端发送通知?-具有.NET服务器的GCM

来自分类Dev

使用XMPP服务器和Google Cloud Messaging(或更新的Firebase Cloud Messaging)进行推送通知的Android聊天应用程序

来自分类Dev

如何使用服务器上的Node从客户端JavaScript上传到Google Cloud Storage?

来自分类Dev

如何在 Google Cloud Platform 上部署 GRPC 服务器和客户端?

来自分类Dev

Bitbar Cloud Appium服务器端JavaScript的测试包内容

Related 相关文章

  1. 1

    Google Cloud Messaging / GCM

  2. 2

    使用GCM在应用上发送通知,返回InvalidRegistration错误

  3. 3

    将Google Cloud Messaging集成到Android App-GCM连接服务器

  4. 4

    服务器端GCM返回错误400

  5. 5

    Firebase Cloud Messaging和C#服务器端代码

  6. 6

    Google Cloud Messaging-CCS(XMPP)与HTTP服务器

  7. 7

    服务器端Google授权

  8. 8

    服务器端Google授权

  9. 9

    GCM服务器端PHP-未经授权的401错误

  10. 10

    与Firebase相关的Google Play服务更新后,Android Google Cloud Messaging(GCM)令牌生成崩溃

  11. 11

    如何使用PHP设置新的Google Cloud Messaging API服务器实现和托管?

  12. 12

    服务器端Google Analytics(分析)实验

  13. 13

    statsd / graphite与Google Analytics(分析)服务器端

  14. 14

    如何验证Google身份服务器端

  15. 15

    Google+服务器端令牌验证

  16. 16

    如何验证Google身份服务器端

  17. 17

    Google Analytics 服务器端 - 隐藏跟踪 ID

  18. 18

    适用于Android和推送通知的Google Cloud Messaging GCM

  19. 19

    接收到UWP Windows 10应用程序的Google Cloud Messaging(GCM)推送通知

  20. 20

    Send push notification using GCM to multiple topics at a time in ios #ios # google-cloud-messaging

  21. 21

    在Android上具有本地设备组的Google Cloud Messaging(GCM)给出了HTTP错误代码401

  22. 22

    在Android上具有本地设备组的Google Cloud Messaging(GCM)给出了HTTP错误代码401

  23. 23

    Google Android Gcm服务器

  24. 24

    发送服务器端 Google Analytics 数据而不发送服务器位置

  25. 25

    如何使用InstanceID从服务器端发送通知?-具有.NET服务器的GCM

  26. 26

    使用XMPP服务器和Google Cloud Messaging(或更新的Firebase Cloud Messaging)进行推送通知的Android聊天应用程序

  27. 27

    如何使用服务器上的Node从客户端JavaScript上传到Google Cloud Storage?

  28. 28

    如何在 Google Cloud Platform 上部署 GRPC 服务器和客户端?

  29. 29

    Bitbar Cloud Appium服务器端JavaScript的测试包内容

热门标签

归档