google Cloud Messaging Push notification

后端 未结 3 2007
时光说笑
时光说笑 2020-12-31 05:23

Can I use POSTMAN client on Google Chrome to send payload message to GCM server for testing purpose. Secondly if yes, what is the header and url parameter to be sent.

相关标签:
3条回答
  • 2020-12-31 05:34

    Yes, you can.

    1. Send a notification with a JSON payload

    URL: https://android.googleapis.com/gcm/send

    Headers:

    • Authorization: key=<your-api-key>
    • Content-Type: application/json

    Body (click on the 'raw' tab):

    {
      "collapse_key": "score_update",
      "time_to_live": 108,
      "delay_while_idle": true,
      "data": {
        "score": "4x8",
        "time": "15:16.2342"
      },
      "registration_ids":["4", "8", "15", "16", "23", "42"]
    }
    

    Note: registration_ids is the only required field, all the others are optional.

    2. Send a notification with a plain text payload

    URL: https://android.googleapis.com/gcm/send

    Headers:

    • Authorization: key=<your-api-key>
    • Content-Type: application/x-www-form-urlencoded;charset=UTF-8

    Body (click on the 'x-www-form-urlencoded' tab):

    collapse_key=score_update
    time_to_live=108
    delay_while_idle=1
    data.score=4x8
    data.time=15:16.2342
    registration_id=42
    

    Note: registration_id is the only required field, all the others are optional.


    Source: https://developer.android.com/google/gcm/http.html

    0 讨论(0)
  • 2020-12-31 05:43

    Yes, you can use POSTMAN.

    This GCM Notification Test Tool simplifies the server side testing immensely by reducing the number of items you enter in POSTMAN everytime - http://techzog.com/development/gcm-notification-test-tool-android/

    0 讨论(0)
  • 2020-12-31 05:57

    Just for the record and to complete the nice answer from @Alexandru Rosianu the GCM endpoint changed a while ago and it is suggested to use the new one. Here is an example taken from the official docs:

    Authentication

    To send a message, the application server issues a POST request. For example:

    https://gcm-http.googleapis.com/gcm/send
    

    A message request is made of 2 parts: HTTP header and HTTP body.

    The HTTP header must contain the following headers:

    • Authorization: key=YOUR_API_KEY
    • Content-Type: application/json for JSON; application/x-www-form-urlencoded;charset=UTF-8 for plain text. If Content-Type is omitted, the format is assumed to be plain text.

    For example:

    Content-Type:application/json
    Authorization:key=YOUR_API_KEY
    
    {
      "notification": {
          "title": "Portugal vs. Denmark",
          "text": "5 to 1"
      },
      "to" : "bk3RNwTe3H0:CI2k_H..."
    }
    

    The HTTP body content depends on whether you're using JSON or plain text. See the Server Reference for a list of all the parameters your JSON or plain text message can contain.

    Example using Curl:

    # curl --header "Authorization: key=YOUR_API_KEY" \
           --header Content-Type:"application/json" \
           https://gcm-http.googleapis.com/gcm/send \
           -d "{\"notification\": { \"title\": \"Portugal vs. Denmark\"," \
              "\"text\": \"5 to 1\" }, \"to\" : \"bk3RNwTe3H0:CI2k_H...\" }"
    
    0 讨论(0)
提交回复
热议问题