Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use GCM with a python GAE backend?

I have a python GAE service, and I want to push notifications from the server to devices. The tutorial available for GCM is written for Java, and runs on ant+Tomcat/Jetty+JAE. I was under the impression that GCM would be a language-agnostic web service, and that I would be able to send push notifications regarding of my server-side platform.

  1. Was I mistaken about GCM being compatible with my python GAE backend?
  2. If I CAN use it with my existing server, what instructions can I follow (or adapt) to get started with sending notifications to a mobile client?
like image 571
user74418 Avatar asked Dec 11 '12 08:12

user74418


2 Answers

Sure you can. GCM has a JSON REST API that you can work against. First you need to register you project here: http://developer.android.com/google/gcm/gs.html.

You basically do this:

  1. Acquire you API key from http://developer.android.com/google/gcm/gs.html#access-key
  2. Construct your payload, a dict containing registration_ids, data etc
  3. Using url.fetch https://developers.google.com/appengine/docs/python/urlfetch/ to send the data as a JSON string to the GCM API

Here's another question with some code. Google Cloud Messaging HTTP Error 400: Bad Request and a blogpost (in not english, i think spanish. but there some sample code) http://pforray.wordpress.com/2012/07/05/ejemplo-gcm-en-appengine-python/

like image 62
fredrik Avatar answered Oct 31 '22 19:10

fredrik


Use gcm-client

pip install gcm-client

Reference:

https://pypi.python.org/pypi/gcm-client/

like image 39
user2805885 Avatar answered Oct 31 '22 20:10

user2805885