3

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!

obelloc
  • 299
  • 1
  • 14
  • 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 Jun 15 '16 at 20:33
  • @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 Jun 16 '16 at 21:03
  • 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 Jun 20 '16 at 17:01
  • Oh, sorry.. yeah, looks like it worked in the past, at least. Mmm, can't remember though. =) – obelloc Jun 20 '16 at 20:45
  • 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 Jun 21 '16 at 10:48

2 Answers2

3

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

Spencer Easton
  • 5,642
  • 1
  • 16
  • 25
  • Thank you, but I have already done all that, and I am still getting the same error. The only difference between my code and yours, is that I am using a URL from the StateTokenBuilder API. I am going to try out a direct URL, and see if I am doing something wrong. – obelloc Jun 02 '15 at 18:07
  • Yea use the webapp url. The /usercallback looks specifically for a state parameter. That means that the returning service needs to return the incoming state. This is a specification of Oauth2 but other services may support. The majority (and specificlly all the google notifications) will POST the notification, so a doPost() function will be your start point. – Spencer Easton Jun 02 '15 at 18:57
  • Well, it is still giving the same error. I have rechecked everything, the app is published as a draft at chrome webstore, the script url is at the webmasters tools and also authorized as a push webhook. I am not using the StateTokenBuilder anymore, but still, no success. ;( – obelloc Jun 02 '15 at 21:00
  • 1
    do you mind posting some code, because I am sure this works as I have a script that uses it daily. – Spencer Easton Jun 02 '15 at 23:34
  • It doesn't seem to work as of 2018. No matter what I do, the Google Cloud Console won't let you verify the GAS web app URL. – Anton Dementiev Jul 08 '18 at 16:13
1

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?

Takashi Matsuo
  • 3,406
  • 16
  • 25
  • 1
    Thanks, I just added a [feature request](https://code.google.com/p/cloud-pubsub/issues/detail?id=16). For now, I finally accomplished to authorize my app domain, after registering the app on the Chrome Web Store (??). I have no idea why this works, though. I just followed this [suggestion](https://github.com/Spencer-Easton/Apps-Script-Gmail-Push-Notifications). – obelloc Jun 02 '15 at 16:10
  • Good to know that. I recommend that you accept Spencer's answer then :) – Takashi Matsuo Jun 02 '15 at 17:28