GithubHelp home page GithubHelp logo

h-nimrod / fcm-push-example Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 227 KB

This is a sample program that sends push notifications using the FCM HTTP v1 protocol.

License: Apache License 2.0

Python 100.00%
android cloud-messaging fcm firebase ios python

fcm-push-example's Introduction

Preparation:

Place the secret key (json) of the Firebase service account, which is generated in the Firebase Console project, into this directory.

$ cp path/to/serviceAccountKey.json sample-app-firebase-adminsdk-foobar.json

This program ues the following modules:

  • argparse
  • json
  • requests
  • oauth2client

If the required modules are not installed, please install them using the command below:

$ pip install argparse json requests oauth2client

Example:

Ensure you have obtained the device token of the desired recipient device.

Send a push notification by specifying the target device's token using the -d option.

$ python send_test.py -d d9pCrwUARmCyWDRjumG2SS:APA91xxxx 
=== Request ===
Request message:  {
    "message": {
        "token": "d9pCrwUARmCyWDRjumG2SS:APA91xxxxx",
        "notification": {
            "title": "Test Notification",
            "body": "This is a sample notification"
        }
    }
}

=== Response ===
Response status code:  200
Response content:  {
  "name": "projects/sample-app/messages/0:1692853925636648%d2dadecfd2dadecf"
}

Command Options:

  • -d DEVICE_TOKEN, --device-token DEVICE_TOKEN: Specify the device token.
  • -p PRIVATE_KEY_JSON_FILE, --private-key-json-file PRIVATE_KEY_JSON_FILE: Specify the secret key of the Firebase service account.
  • -m MESSAGE_JSON, --message-json MESSAGE_JSON: Specify the json file of the push notification message to be sent.
  • -t TITLE, --title TITLE: Specify title to set for the push notification.
  • -b BODY, --body BODY: Specify body to set for the push notification.
  • -i IMAGE, --image IMAGE: Specify image icon url to set for the push notification.
  • --print-access-token: Display the bearer token used for FCM HTTP v1 protocol.

Reference Site:

fcm-push-example's People

Contributors

h-nimrod avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

fcm-push-example's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.