官方给的demo代码如下:
request = PushMessageToAndroidRequest.PushMessageToAndroidRequest()
request.set_AppKey(appKey)
request.set_Target('ALL')
request.set_TargetValue('ALL')
request.set_Title("PushMessageToAndroid title")
request.set_Body("Message from ali push Open Api2.0 : PushMessageToAndroid")
request.add_query_param('AndroidNotificationChannel', '1')
result = clt.do_action(request)
print result
这个代码有两个问题,如果和另外一份demo代码中的:
clt = client.AcsClient(properties.accessKeyId,properties.accessKeySecret,properties.regionId)
request = PushMessageToAndroidRequest.PushMessageToAndroidRequest()
request.set_AppKey(properties.appKey)
request.set_Target('ALL')
request.set_TargetValue('ALL')
request.set_Title("PushMessageToAndroid title")
request.set_Body("Message from ali push Open Api2.0 : PushMessageToAndroid")
result = clt.do_action(request)
很可能会出现下面的错误信息:
EABF26DA-89EA-44BA-B16E-117FE03D29C7
cloudpush.aliyuncs.com
Throttling.User
Request was denied due to user flow control.
这个错误信息按照官方的解释是限流了,但是实际并不是,可以尝试分开调用,不要连续进行push message和push notice。
另外一个问题是: 这份代码在对于最新的安卓8.0以上系统的消息无法正常弹出,按照文档解释需要设置NotificationChannel(文档链接:https://help.aliyun.com/knowledge_detail/67398.html)。