I am trying to retrieve subscription information from Google when I receive a Real Time Notification from Google Pub/Sub. Google Pub/Sub is sending me subscription token in this format:
{"message":{"data":"REALLY LONG STRING","messageId":"468103560112704","message_id":"468103560112704","publishTime":"2019-03-18T17:19:01.444Z","publish_time":"2019-03-18T17:19:01.444Z"},"subscription":"my/pubsub/subscriptions/path"}
I don't believe that this is the format that a subscription token is supposed to arrive in, and when I send it to Google to retrieve information using an HTTP GET command, I get nothing, no errors and no data. I think that it is just a generic message. I would think that I am doing everything right because I am actually getting messages when I expect to get them during testing, I just can't do anything useful with them. Any thoughts at all on how to get these converted to REAL messages???
This one took far to long to figure out, and the solution turned out to be quite simple. I was surprised that for two weeks, nobody at Google could find an answer to this question for me. It turns out that this is the correct format for the Pub/Sub message. The JSON message that I was receiving from PubSub was in a VERY different format from what I was expecting based on the Google Play documentation, and basically just had a "data" field that looked like a token, but it wasn't. I actually had to dive into the PubSub documentation deep and found an obscure note on the "data" field - it is a base64 encoded string. If you decode the "data" field, voila!, you get a JSON string containing the subscription purchaseToken that you need to query Google Play for subcription information.
So there is a JSON message INSIDE of this JSON message, but it is base64 encoded, and you just need to decode it to get to the expected treasure inside.