3

我正在尝试使用 Google Cloud Scheduler 向我的应用发送推送:

gcloud beta scheduler jobs create http PUSH --schedule="0 * * * *" --uri="https://fcm.googleapis.com/fcm/send" --description="desc" --headers="Authorization: key=<AUTHKEY> --http-method="POST" --message-body="{\"to\":\"/topics/allDevices\",\"priority\":\"low\",\"data\":{\"success\":\"ok\"}}"    

结果始终是 401 Unauthorized。发出命令后:

gcloud beta scheduler jobs describe PUSH

我没有得到这些标题:

description: desc
httpTarget:
  body: eyJ0byI6Ii90b3BpY3MvYWxsnByaW9yaXR5IjoRGV2aWNlcyIsIiaGlnaCIsImRhdGEiOnsic3VjY2VzcyI6Im9rIn19  <--- THIS IS WEIRD
  headers:
    Content-Type: application/octet-stream
    User-Agent: Google-Cloud-Scheduler
  httpMethod: POST
  uri: https://fcm.googleapis.com/fcm/send
lastAttemptTime: '2018-11-07T20:32:37.657408Z'
name: projects/..../locations/europe-west1/jobs/PUSH
retryConfig:
  maxBackoffDuration: 3600s
  maxDoublings: 16
  maxRetryDuration: 0s
  minBackoffDuration: 5s
schedule: 0 * * * *
scheduleTime: '2018-11-07T21:00:00.681498Z'
state: ENABLED
status:
  code: 16
timeZone: Etc/UTC
userUpdateTime: '2018-11-07T20:29:15Z'
4

1 回答 1

5

关于身体的第一个问题:

正文:eyJ0byI6Ii90b3BpY3MvYWxsnByaW9yaXR5IjoRGV2aWNlcyIsIiaGlnaCIsImRhdGEiOnsic3VjY2VzcyI6Im9rIn19 <--- 这很奇怪

这是base64编码

{\"to\":\"/topics/allDevices\",\"priority\":\"low\",\"data\":{\"success\":\"ok\"}}

谷歌正在接受您--message-body并将其编码为base64.

接下来关于标题问题。您的“--headers”中有几个错误。

--headers="授权:key=AUTHKEY

您在 . 之后缺少引号AUTHKEY。我会假设这个问题只是创建问题的编辑错误。(请注意,我无法弄清楚如何在此响应中包含小于和大于字符)。

但是,for 的语法--headers是错误的。--headers期望,KEY=VALUE不是KEY:VALUE。在这个例子中KEYisAuthorization和 the VALUEis key=AUTHKEY

--headers="Authorization=key=AUTHKEY"
于 2018-11-07T23:06:28.233 回答