简体   繁体   中英

php publish message to google cloud pubsub

How do I post a message to a topic using curl (or PHP). I tried copy/paste'ing the sample code an I get an error: Invalid JSON payload received Any help would be appreciated!

curl -X POST https://pubsub.googleapis.com/v1/projects/[projectname]/topics/[topicname]:publish
     -H "Content-Type: application/json"
     -H "Authorization: key=[mykey]"
     -d '{"name": "name", "email": "email"}'

Please try to put your data inside the messages tag.

For your case, please try

curl -X POST \
  https://pubsub.googleapis.com/v1/projects/[projectname]/topics/[topicname]:publish \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Authorization: Bearer <<generated access token>>' 
  -H 'Content-Type: application/json' \
  -H 'Host: pubsub.googleapis.com' \
  -d '{
  "messages": [
    {
      "name": "name", "email": "email"
    }
  ]
}'

Please let us know if you encounter any further problem. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM