| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e4aff7e commit 363166b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,6 +245,29 @@ def send_all(): | |||
| 245 | 245 | # [END send_all] | |
| 246 | 246 | ||
| 247 | 247 | ||
| 248 | + def send_each(): | ||
| 249 | + registration_token = 'YOUR_REGISTRATION_TOKEN' | ||
| 250 | + # [START send_each] | ||
| 251 | + # Create a list containing up to 500 messages. | ||
| 252 | + messages = [ | ||
| 253 | + messaging.Message( | ||
| 254 | + notification=messaging.Notification('Price drop', '5% off all electronics'), | ||
| 255 | + token=registration_token, | ||
| 256 | + ), | ||
| 257 | + # ... | ||
| 258 | + messaging.Message( | ||
| 259 | + notification=messaging.Notification('Price drop', '2% off all books'), | ||
| 260 | + topic='readers-club', | ||
| 261 | + ), | ||
| 262 | + ] | ||
| 263 | + | ||
| 264 | + response = messaging.send_each(messages) | ||
| 265 | + # See the BatchResponse reference documentation | ||
| 266 | + # for the contents of response. | ||
| 267 | + print('{0} messages were sent successfully'.format(response.success_count)) | ||
| 268 | + # [END send_each] | ||
| 269 | + | ||
| 270 | + | ||
| 248 | 271 | def send_multicast(): | |
| 249 | 272 | # [START send_multicast] | |
| 250 | 273 | # Create a list containing up to 500 registration tokens. | |
@@ -289,3 +312,28 @@ def send_multicast_and_handle_errors(): | |||
| 289 | 312 | failed_tokens.append(registration_tokens[idx]) | |
| 290 | 313 | print('List of tokens that caused failures: {0}'.format(failed_tokens)) | |
| 291 | 314 | # [END send_multicast_error] | |
| 315 | + | ||
| 316 | + | ||
| 317 | + def send_each_for_multicast_and_handle_errors(): | ||
| 318 | + # [START send_each_for_multicast_error] | ||
| 319 | + # These registration tokens come from the client FCM SDKs. | ||
| 320 | + registration_tokens = [ | ||
| 321 | + 'YOUR_REGISTRATION_TOKEN_1', | ||
| 322 | + # ... | ||
| 323 | + 'YOUR_REGISTRATION_TOKEN_N', | ||
| 324 | + ] | ||
| 325 | + | ||
| 326 | + message = messaging.MulticastMessage( | ||
| 327 | + data={'score': '850', 'time': '2:45'}, | ||
| 328 | + tokens=registration_tokens, | ||
| 329 | + ) | ||
| 330 | + response = messaging.send_each_for_multicast(message) | ||
| 331 | + if response.failure_count > 0: | ||
| 332 | + responses = response.responses | ||
| 333 | + failed_tokens = [] | ||
| 334 | + for idx, resp in enumerate(responses): | ||
| 335 | + if not resp.success: | ||
| 336 | + # The order of responses corresponds to the order of the registration tokens. | ||
| 337 | + failed_tokens.append(registration_tokens[idx]) | ||
| 338 | + print('List of tokens that caused failures: {0}'.format(failed_tokens)) | ||
| 339 | + # [END send_each_for_multicast_error] | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments