我对Onesignal绝对陌生,并且在将其集成到pyFlask中时遇到问题。我的其余API在所有设备上的React App上发送推送通知,但现在我希望它发送应用程序的特定用户。谁能帮我提供代码?是否有人可以通过代码帮助我发送特定用户
from onesignal import OneSignal, SegmentNotification
client = OneSignal("key", "key")
notification_to_all_users = SegmentNotification(
contents={
"en": "Hello from OneSignal-Notifications"
},
included_segments=[SegmentNotification.ALL]
)
client.send(notification_to_all_users)
答案 0 :(得分:0)
尝试以下代码:
import onesignal as onesignal_sdk
payload = {
"included_segments": ["All"],
"contents": {"en": "Lorem ipsum dolor amit falit matit", "ru": "Lorem ipsum dolor amit falit matit"},
"android_gcm_sender_id": "XXXX",
"android_channel_id":"XXXX",
"android_group": "myapp",
"android_group_message": "MYAPP",
"large_icon": "https://img.onesignal.com/n/bf627043.png",
"android_visibility": 1,
"priority": 5,
"android_sound":"notification",
"headings": {"en": "New post"}
}
# create a onesignal client
onesignal_client = onesignal_sdk.Client(
app_auth_key="XXXX",
app_id="XXXX"
)
# create a notification
new_notification = onesignal_sdk.Notification(post_body=payload)
# Send notification
onesignal_response = onesignal_client.send_notification(new_notification)