Python-gcm问题,GCM服务器没有响应

时间:2015-04-21 04:36:16

标签: android python google-cloud-messaging chrome-gcm

我目前正在尝试使用python-gcm完成Android推送通知,并且遇到了我在推送通知时没有收到GCM服务器响应的问题。

我已经确认我收到了device_id,并且正在使用的API密钥/发件人ID是正确的,并且在我点击GCM服务器后我收到了成功的回复,但我仍然看不到推送通知显示在我的设备上。

这通常只是因为我在Google Developer Console中设置GCM的方式不正确吗?

第一次执行此操作时,我确信可能会有一些我错过的常见内容。

下面是我设置的样本flask-gcm代码。我收到了成功的回复,谷歌设置方面一定有一些东西我想的。

 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"

0 个答案:

没有答案