0

I am currently trying to finish implementing Android push notifications with python-gcm and am running into issues where I am not getting a response from the GCM server when I push the notifications.

I have verified that I am getting the device_id, and that the API key / sender ID's being used are correct, and I am getting a successful response back once I hit the GCM server, but I still see no push notifications showing up on my device.

Is this usually just because the way I have the GCM set up in the Google Developer Console is not correct?

First time implementing this so I'm sure there may just be something common I've missed.

Below is the sample flask-gcm code that I have set up. I am receiving a success response back, there must be something missing on the google setup side I am thinking.

 if device.platform == 'Android':
        # data = {'param1': 'value1', 'param2': 'value2'}
        data = {'data': message}

        # Set the device id
        reg_id = device.device_id

        Logger.info('Before sending the push JSON ' + str(reg_id))

        # Pass in the reg id of who to send to
        multicast = JSONMessage([reg_id], data, dry_run=False)

        try:
            # attempt send
            res_multicast = gcm_service.send(multicast)

            for res in [res_multicast]:
                # nothing to do on success
                for reg_id, msg_id in res.success.items():
                    Logger.info("Successfully sent %s as %s" % (reg_id, msg_id))
                    Logger.info("THIS IS THE REG ID THAT WAS SENT TO: " + str(reg_id))
                    Logger.info("THIS IS THE MESSAGE ID THAT WAS SENT " + str(msg_id))
                    Logger.info("RES SUCESS ITEMS: " + str(res.success.items()))

                # update your registration ID's
                for reg_id, new_reg_id in res.canonical.items():
                    Logger.info("Replacing %s with %s in database" % (reg_id, new_reg_id))

                # probably app was uninstalled
                for reg_id in res.not_registered:
                    Logger.info("Removing %s from database" % reg_id)

                # unrecoverably failed, these ID's will not be retried
                # consult GCM manual for all error codes
                for reg_id, err_code in res.failed.items():
                    Logger.info("Removing %s because %s" % (reg_id, err_code))

                # if some registration ID's have recoverably failed
                if res.needs_retry():
                    # construct new message with only failed regids
                    retry_msg = res.retry()
                    # you have to wait before attemting again. delay()
                    # will tell you how long to wait depending on your
                    # current retry counter, starting from 0.
                    # Logger.info("Wait or schedule task after %s seconds" % res.delay(retry))
                    # retry += 1 and send retry_msg again

        except GCMAuthenticationError:
                # stop and fix your settings
                print "Your Google API key is rejected"
        except ValueError, e:
                # probably your extra options, such as time_to_live,
                # are invalid. Read error message for more info.
                print "Invalid message/option or invalid GCM response"
                print e.args[0]
        except Exception:
                # your network is down or maybe proxy settings
                # are broken. when problem is resolved, you can
                # retry the whole message.
                print "Something wrong with requests library"
parchambeau
  • 1,141
  • 9
  • 34
  • 56

0 Answers0