GithubHelp home page GithubHelp logo

bogdal / django-gcm Goto Github PK

View Code? Open in Web Editor NEW
98.0 98.0 42.0 106 KB

Google Cloud Messaging Server in Django

Home Page: https://django-gcm.readthedocs.org

License: BSD 2-Clause "Simplified" License

Makefile 0.30% Python 98.29% HTML 1.41%

django-gcm's People

Contributors

bogdal avatar bradmontgomery avatar chitrank-dixit avatar ddwiyaksha avatar dheerendrarathor avatar kasperbrandt avatar melug avatar northshoot avatar ogranada avatar rclsilver avatar speenah avatar tasn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-gcm's Issues

Support for bulk push

It would be really awesome if it had support for bulk push. If its already implemented, where can I get docs on using it.

Thanks,
Mevin

Practical reason for the model ordering on Device LastUpdated?

Hi, thanks for making this app!

Just wondering why there's a forced queryset ordering on the lastupdated field for a device? If I have an incredibly large number of devices and I need to evaluate them in a queryset for any reason, there's an unnecessary expensive sort placed on them. I get why you'd want to do it for maybe the admin form but at the model level I'm not sure it's worth the performance hit?

can't add unique constraint on reg_id column because it's a TEXT field not VARCHAR on MySQL

From the change 3 days ago but it only showed up today in our Jenkins builds :-(

Error in migration: vcm:0002_auto__chg_field_device_reg_id__add_unique_device_reg_id
STDERR: FATAL ERROR - The following SQL query failed: ALTER TABLE gcm_device ADD CONSTRAINT gcm_device_reg_id_1d569ade4b517e81_uniq UNIQUE (reg_id)
The error was: (1170, "BLOB/TEXT column 'reg_id' used in key specification without a key length")

I think it has to be turned into a varchar field first...

Not compatible with django 1.9

since dependency on tasty, the gcm is not compatible with 1.9 due to django-tastypie/django-tastypie#1395

Moreover, as disscussed there, get_cache has been removed from django, which is used by tasty

It does work with version django-tastypie-0.12.2.dev0 which is not in the pip repo. The dependencies could be updated.

gcm 3.0 topic

How to use gcm with topic subscribing support?
If i put in send_message() to parameter, i get error bad request.

Overriding the send function in api.GCMMessage

I would like to add a few optional arguments to the

    values = {
        'registration_ids': regs_id,
        'collapse_key': collapse_key,
        'data': data
    }

How can I do that ?. Is there an easy way to override this ?

Saving device model on unregister endpoint

Hi,

Currently the unregister endpoint is saving the dev_id for marking them inactive. Now the issue is:
If some user decides to send false dev_id (without reg_id) to unregister endpoint, The dev_id will be stored with reg_id = null. Now if the same user again send the false dev_id, this will cause IntegrityError: duplicate key value violates unique constraint "gcm_device_reg_id_key" DETAIL: Key (reg_id)=() already exists., which will send repeated mails to django site admin.

I want to know your views on this.

how to send message?

I have installed django-gcm and the android client. The android app is already install and I can see in admin page it was register but how can I send message to the android client? Sorry if i miss the documentation.

Question for dev_id usage.

In model why dev_id is unique but reg_id is not? And what is dev_id for?
And reg_id is TextField, why?

Failing to pip install django-gcm due to dependencies

I have tried to install django-gcm but it's failing due to a dependency on django-tastypie. I also tried to install django-tastypie first but django-gcm still fails to install. Currently, django-gcm 1.0.6 is working and installing. It's just 1.0.7 that is failing for me to install.

$ pip install django-gcm
Collecting django-gcm
Downloading django-gcm-1.0.7.tar.gz
Requirement already satisfied (use --upgrade to upgrade): django>=1.6 in /home/vagrant/virtualenvs/nextdrop/lib/python2.7/site-packages (from django-gcm)
Collecting django-tastypie>=0.12.2-dev (from django-gcm)

Could not find a version that satisfies the requirement django-tastypie>=0.12.2-dev (from django-gcm) (from versions: 0.9.6, 0.9.7, 0.9.9, 0.9.10, 0.9.11, 0.9.12, 0.9.13, 0.9.14, 0.9.15, 0.9.16, 0.10.0, 0.11.0, 0.11.1, 0.12.0, 0.12.1)
No matching distribution found for django-tastypie>=0.12.2-dev (from django-gcm)

Extend model

I may be being dumb, Is it possible to somehow extend the model to store additional data about the user without modifying the package? Or would the best way be to modify the package? Say if I wanted a link to a User or something?

compatibility with Django 1.10

django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. urlpatterns should be updated to be a list of django.conf.urls.url() instances instead.

M2M field for users

Shouldn't the AbstractDevice model have a M2M field mapping to users from the auth_user table? I believe this app should have a built in way of mapping to users.

Logging

Currently there is nothing logged in entire repository. There are only 2 singals and that are for register and unregister. I want to add Logging at various points like message sent, failure received, device_id and failing reason mapping etc.

I'll create a PR if required.

curl request incomplete

The requests provided in the documentation won't work when adding user field to device. Instead of:
curl -X POST -H "Content-Type: application/json" -d '{"dev_id": "test", "reg_id":"abcd", "name":"test device"}' http://localhost:8000/gcm/v1/device/register/
it should be:
curl -X POST -H "Authorization: apikey [email protected]:<api_key>" -H "Content-Type: application/json" -d '{"dev_id": "test", "reg_id":"abcd", "name":"test device"}' http://localhost:8000/gcm/v1/device/register/

Documentation too sparse.

GCM Application server in Django is definitely a great idea and it would be very useful if only I could understand how to use it.
Unfortunately, IMHO the documentation is too sparse to understand the usage completely.
Adding some detailed docs would be a great enhancement, and will also help some developers contribute to this project.

Some quick points on what the docs need.

(1) How django-gcm fits in the GCM architecture, http://developer.android.com/google/gcm/gcm.html?

(2) Giving a general idea of why is a GCM Application server necessary, and what are the gaps django-gcm fills up.

(3) A complete tutorial explaining the 3 step working (Registration, Sending Message and Receiving Message) of GCM with django-gcm and the sample app that you have created as a separate repository. (A PDF or online blog link that explains this with some snapshots will be nice)

I will add some nice docs if I understand how to use it.

Wrong pytz dependency

Please, fix wrong pytz version dependency. Does it really works only with pytz==2013.8 and not with any later versoin???

Support for Device groups

One functionality that is not currently supported by django-gcm is support for device groups. This would allow multiple devices to be registered on one notification key. Is this something that could be supported in the model of Django-gcm?

Angular POST request causes 400

While registering a device with required parameters through angular, I get a 400 from the server.

var req = {
         method: 'POST', 
         url: base_url,
         headers: {
            'Content-Type': 'application/json',
            }, 
         data: data,        
        }

        $http(req).
        then(function(response){
            deferred.resolve(response);
        }, function(data){
            console.error(JSON.stringify(data));
            deferred.reject();
        });

This is the error response from the server:

{
    "data":{},
    "status":400,
    "config":{"method":"POST","transformRequest":[null],"transformResponse": [null],"url":"http://192.168.0.103:8000/gcm/v1/device/register/","headers":{"Content-Type":"application/json","Accept":"application/json, text/plain, */*"},
    "data":{"dev_id":"test","reg_id":"test","name":"Test"}},
    "statusText":"BAD REQUEST"
}

A valid POST request is being sent from the client side, it is possible that the data is available in request.data rather than request,POST, in this case, it is probably causing an error in de-serailisation.

Documentation

There are few documentation issues/hurdle to get things working:

  1. So once one installs django-gcm one has to run following commands right?

python manage.py syncdb
python manage.py migrate

  1. In settings.py one should be entering key generated for server app, browser app or Android app for GCM_KEYS?
  2. I compiled the associated android pager program and installed it on my system.
    I got what one needs to set GCM_SENDER project number from google app server.

But not clear what should value of API_URL should be?

static public String API_URL = "<url_to_your_application>/gcm/v1/device/";

If someone can show me how to get this working, I will be more than happy to update documentation.

-Subodh

Upstream messages

Hi,

do you have any plans to integrate XMMP and some API for upstream messages?

getting status code: 500

Hi,
i register with reg_id and dev_id, and then call gcm register on my server, i get message SUCCESS, but:

status code: 500

and then GCM doesn't work..
how can i debug this?

Support for Google's XMPP based Cloud Connection Server (CCS)

Are there plans to support Google Cloud Messaging (GCM) Cloud Connection Server (CCS) as well?? Its XMPP based instead of HTTP. It has many advantages over sending messages via HTTP.

We already use this library in our app but after facing reliability/consistency issues with GCM, we're looking into an XMPP based solution.

Problem with extending model

I have a problem with extending the model, when I try to python manage.py makemigrations gcm, the console tells me there is no changes and I cannot migrate anything.

gcm/v1/device/register/ POST request fails after extending device model in django-gcm.

gcm/v1/device/register/ post request works perfect with default django-gcm model but if I extend device model to add user field and make POST request, it fails without any response.

My extended model is as follows,

####models.py

from django.conf import settings from django.db import models
from gcm.models import AbstractDevice

class Device(AbstractDevice):
user = models.ForeignKey(settings.AUTH_USER_MODEL)

####Added my app url in main urls.py

url(r'', include('contrib.device.urls')),

####my app urls.py

from django.conf.urls import patterns, include, url
from tastypie.api import Api
from .resources import AuthResource

gcm_api = Api(api_name='v1')
gcm_api.register(AuthResource())

urlpatterns = patterns('',
url(r'^gcm/', include(gcm_api.urls)),
)

####resources.py

from gcm.resources import DeviceResource
from tastypie.authentication import ApiKeyAuthentication

class AuthResource(DeviceResource):

class Meta(DeviceResource.Meta):                                                                                                              
    authentication = ApiKeyAuthentication()                                                                                                   

def get_queryset(self):                                                                                                                       
    qs = super(AuthResource, self).get_queryset()                                                                                             
    # to make sure that user can update only his own devices                                                                                  
    return qs.filter(user=self.request.user)                                                                                                  

def form_valid(self, form):                                                                                                                   
    form.instance.user = self.request.user                                                                                                    
    return super(AuthResource, self).form_valid(form) 
#### Code added in settings.py
App added under INSTALLED_APPs

'contrib.device',
'tastypie',
'gcm',

Variables added

GCM_APIKEY = "My App key"
GCM_DEVICE_MODEL = 'contrib.device.models.Device'

What I am doing wrong? Please help.

Thank you.

apikey project doesn´t work

When checking out the API-key project and attempting to register a device, I get a bad request
However, the data passed is OK. This is my first time using Django, I don´t know where to look for further information.

Also, a new ApiKey is not generated upon creating a new user. As far as I can see from the documentation, this should have happened?

escalation of exceptions with tag 1.2.0

Hey, I am trying the 1.2.0 tag, to send the comment
python manage.py gcm_messenger 1 'my test message'
which result in a escalation of errors, and I don't see the obvious reason:

/usr/local/lib/python3.5/site-packages/django/core/management/base.py:265: RemovedInDjango110Warning: OptionParser usage for Django management commands is deprecated, use ArgumentParser instead
RemovedInDjango110Warning)

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 137, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/usr/local/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 67, in create_connection
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 728, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
body=body, headers=headers)
File "/usr/local/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 345, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 784, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 217, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 146, in _new_conn
self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x10956c898>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/requests/adapters.py", line 376, in send
timeout=timeout
File "/usr/local/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 609, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.5/site-packages/requests/packages/urllib3/util/retry.py", line 273, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='gcm-http.googleapis.com', port=443): Max retries exceeded with url: /gcm/send (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x10956c898>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/site-packages/django/core/management/init.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/site-packages/django/core/management/init.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(_args, *_cmd_options)
File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(_args, *_options)
File "/usr/local/lib/python3.5/site-packages/django_gcm-1.2.0-py3.5.egg/gcm/management/commands/gcm_messenger.py", line 54, in handle
{'message': message}, collapse_key=collapse_key)
File "/usr/local/lib/python3.5/site-packages/django_gcm-1.2.0-py3.5.egg/gcm/models.py", line 91, in send_message
registration_ids=[self.reg_id], data=data, *_kwargs)
File "/usr/local/lib/python3.5/site-packages/django_gcm-1.2.0-py3.5.egg/gcm/models.py", line 28, in send
data, registration_ids=registration_ids, *_kwargs)
File "/usr/local/lib/python3.5/site-packages/django_gcm-1.2.0-py3.5.egg/gcm/api.py", line 65, in send
data=values, headers=headers)
File "/usr/local/lib/python3.5/site-packages/requests/api.py", line 107, in post
return request('post', url, data=data, json=json, *_kwargs)
File "/usr/local/lib/python3.5/site-packages/requests/api.py", line 53, in request
return session.request(method=method, url=url, *_kwargs)
File "/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, *_send_kwargs)
File "/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, *_kwargs)
File "/usr/local/lib/python3.5/site-packages/requests/adapters.py", line 437, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='gcm-http.googleapis.com', port=443): Max retries exceeded with url: /gcm/send (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x10956c898>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))

django-gcm issue with sending message

I have followed the django-gcm documentation to setup gcm for my project. I was experiencing problems while sending message to gcm registered device, I was able to send something to the gcm registered device but on the android device it was coming as null. Here is the link I am following

http://django-gcm.readthedocs.org/en/latest/sending_messages.html

so I changed this line
my_phone.send_message('my test message', collapse_key='something')

to
my_phone.send_message({'message':'my test message'}, collapse_key='something')

and it got working fine for me and I am receiving a proper message so I am suggesting a little change in the documentation so that others won't get into problems.

Canonical IDs support

Canonical IDs are sent as a response by the GCM server in case the registration ID changes for a client. The number of canonical IDs are given by the "canonical_ids" key in the response JSON. For the corresponding recipient, the registration_id on the server should be replaced by this canonical ID.

The response body format is given here: https://developers.google.com/cloud-messaging/http#response

Please check the 2nd example from this link : https://developers.google.com/cloud-messaging/http#example-responses

Device name not added after registration

Hi,

I'm sending a JSON payload of the following form

'{"reg_id": "<registration id>", "dev_id": "<device id>", "name": "A Device"}'

Running $./manage.py gcm_messenger --devices gives me the following.

(#1) None

The device is registered, but the name is set to None, for some reason. Any idea why that might be happening?

PS: Thanks for the great work :-)

sending 4 messages

I have problem, gcm is sending 4 messages when rest save object.
Does anyone else had this problem?

message omitted after space

I am encountering an issue that when i send a message , the message string after a space is omitted.
e.g. if i send "check now"
Only check is being shown in the Dialog.

Edit : This is happening when i am sending messages from console.
There is no problem if i send messages from python manage.py shell.

Delay when sending over 20 messages

Hi,

I am using this function to push messages to my devices and I've got some problems. The first 20 messages are received instantly but after 20, there is delays (like 30 secondes and more).
Device.objects.all().send_message({'id': '{}'.format(msg),})

This problem is not present when I push from "phpfiddle.org" for example.

Thank You

No JSON object could be decoded

Hey,

I am able to register the device, but when I try sending a message even by django orm, I get this error.
Traceback (most recent call last):
File "", line 1, in
File "/app/.heroku/python/lib/python2.7/site-packages/gcm/models.py", line 37, in send_message
collapse_key=collapse_key)
File "/app/.heroku/python/lib/python2.7/site-packages/gcm/api.py", line 33, in send_gcm_message
return json.loads(response.content)
File "/app/.heroku/python/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s)
File "/app/.heroku/python/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/app/.heroku/python/lib/python2.7/json/decoder.py", line 383, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Is the dict file here not been decoded.

It works when I use it with my development server. But when I try doing it from heroku this is the error I receive.

Cheers,
Yogesh

Handling of responses from GCM server

The GCM server has responses in JSON that need to be handled. I have the link here:
http://developer.android.com/google/gcm/http.html

error: String describing an error that occurred while processing the message for that recipient. The possible values are the same as documented in the above table, plus "Unavailable" (meaning GCM servers were busy and could not process the message for that particular recipient, so it could be retried).

Is this not supported? Couldn't find anything on the documentation for this.

I have it implemented locally on my side for this.

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.