What Bearer token should I be using for Firebase Cloud Messaging testing?

前端 未结 5 646
半阙折子戏
半阙折子戏 2020-12-29 06:45

I am trying to send a test notification using Firebase Cloud Messaging via Postman. I\'m doing a POST to this url

https://fcm.googleapis.com/v1/projects/[my         


        
5条回答
  •  生来不讨喜
    2020-12-29 07:26

    Steps to get Authentication Bearer:

    1. Got to Google OAuth Playground: https://developers.google.com/oauthplayground
    2. In the "Input your own scopes" for FCM use this url: https://www.googleapis.com/auth/firebase.messaging
    3. Tap Authorize API.
    4. Pick correct user for authorisation and allow access.
    5. In the Step 2: Exchange authorization code for tokens tap Exchange authorisation code for tokens.
    6. Access token is your Bearer.

    Steps to send FCM throw Postman:

    1. URL to send: https://fcm.googleapis.com/v1/projects/projectid-34543/messages:send
    2. Request Type: POST
    3. Headers: Content-Type -> application/json & Authorization -> Bearer
    4. In the body section enter APS payload with the right device token.
    5. Click send.

    In case you want to use cURL, for a data-notification:

    curl --location --request POST 'https://fcm.googleapis.com/v1/projects/your-project-id/messages:send' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer your-access-token-*****-wqewe' \
    --data-raw '{
        "message": {
            "token": "device-token-qwfqwee-***-qefwe",
            "data": {
                "Key1": "val1",
                "Key2": "val2"
            }
        }
    }'
    

提交回复
热议问题