我有一个简单的 Web 服务应用程序,我用它来测试从 Python 通过 Parse.com 发送推送。
我的应用程序使用 Flask 模块和ParsePy 模块。下面列出的代码适用于 Push.alert(notification, channels=["pushDebug"])
- 我在订阅该频道的设备上看到通知。
现在我正在尝试向特定设备 ID 发送推送,但没有看到通知通过。
为特定用户 ID(Parse 中定义的自定义字段)定义“Where”查询的正确语法是什么?这是需要此查询的代码行:Push.alert(notification, where={"kDeviceID": str(deviceID)})
我发现的例子
Push.alert({"alert": "The Mets scored! The game is now tied 1-1.",
"badge": "Increment", "title": "Mets Score"}, channels=["Mets"],
where={"scores": True})
"where": {
"user_id": "user_123"
}
我的网络服务:
from flask import Flask
from flask import Response, jsonify, request, redirect, url_for
from parse_rest.connection import register
from parse_rest.installation import Push
import socket
app = Flask(__name__)
didRegisterWithParse = 0
def checkRegister():
if didRegisterWithParse == 0:
register(
"APPLICATION_ID",
"REST_API_KEY",
master_key="MASTER_KEY"
)
global didRegisterWithParse
didRegisterWithParse = 1
return
@app.route('/testparsepush/')
def testparsepush():
deviceID = request.args.get('device_id')
hostString = "http://%s:5000/getcommand/" % socket.gethostbyname(socket.gethostname())
notification = {"alert": "Parse Test","title": "Push from Python", "host": hostString}
checkRegister()
# send push notification through parse
resp = None
if deviceID:
Push.alert(notification, where={"kDeviceID": str(deviceID)})
#prepare response
resp = jsonify(message = 'sent alert to deviceID: ' + str(deviceID))
else:
Push.alert(notification, channels=["pushDebug"])
resp = jsonify(message = 'sent alert to channel pushDebug')
resp.status_code = 200
return resp
if __name__ == '__main__':
print(socket.gethostbyname(socket.gethostname()))
app.run(host='0.0.0.0')