3
votes

I have been playing around with the Pub/Sub REST API on Google App Script.

I have tried, without success, to create a subscriber with a push end point at script.google.com. The push end point URL was created with the StateTokenBuilder API, which requires a query parameter to be present on the end point URL. The query parameter is further used to forward any request at the URL to a javascript function inside the app.

Is it allowed to have a push end point URL with a query parameter?

However, even if it is allowed, I am unable to register for a push end point at the domain script.google.com. I am required to assert ownership of any domain other than appspot.com.

Do you guys know of any workaround? Am I doing something wrong?

This is the error I am getting:

  "error": {
    "code": 400,
    "message": "Invalid push endpoint given (endpoint=https://script.google.com/macros/s/.../usercallback?state=...). Refer to https://cloud.google.com/pubsub/subscriber#create for more information.",
    "status": "INVALID_ARGUMENT"
  }

Thank you!

2
In the feature request you say this did start working for you when you published to the web store. I'm getting a similar error ("The supplied HTTP URL is not registered in the project that owns the subscription"). Was there a delay once you'd published before it started working? - Andrew Roberts
@Andrew Well, I don't remenber saying that. Actually, I re-read my feature request, and all I could find was somebody else claiming that. So, I guess that workaround didn't workout for me - but, honestly, I don't remember anymore. =) - obelloc
FYI It was actually in the comments to Takashi Matsuo's answer that you said you'd got it working. But thanks anyway (still can't get it working myself). - Andrew Roberts
Oh, sorry.. yeah, looks like it worked in the past, at least. Mmm, can't remember though. =) - obelloc
I have since got the Drive API to accept my app's URL as the URL for push notifications, no luck with pub/sub though. - Andrew Roberts

2 Answers

3
votes

I was able to get Cloud Pub/Sub Working with Apps Script. The trick is to publish your script to the chrome web store (you can leave it in draft mode). This will verify your script in webmaster tools. You then go to the Dev Console and add the published URL of the script without the trailing /exec to your push locations.

Here is an example of the new gmail push notifications that uses Pub/Sub.
https://github.com/Spencer-Easton/Apps-Script-Gmail-Push-Notifications

1
votes

Is it allowed to have a push end point URL with a query parameter?

Yes.

Do you guys know of any workaround? Am I doing something wrong?

As you noticed, now we don't support push endpoints with the domain "script.google.com". I think this is a good feature request. Do you mind adding a feature request on our issue tracker?