I followed this tutorial from the GAS team.
Adding voice and SMS to Google Apps using Twilio and Apps Script
However, when I modify the TwiML as per the Twilio Docs to add <Redirect> upon timeout, I get an "Application Error".
<Response>
<Gather action="https://script.google.com/macros/s/SCRIPT_ID/exec" numDigits="1" timeout="10">
<Say>Welcome to Yard Stars</Say>
<Say>To schedule a Sprinkler Service visit, press 1.</Say>
<Say>To discuss a new Sprinkler System, press 2.</Say>
<Say>To speak with someone in accounting, press 3.</Say>
</Gather>
<Say>Sorry, I didn't get your response.</Say>
<Redirect method="GET">https://script.google.com/macros/s/SCRIPT_ID/exec</Redirect>
</Response>
One thing that I noticed is that GAS is sending back "Transfer-Encoding Chunked" which Twilio does not support.
However it appears to only effect the Redirect Call.
Any idea of a workaround how I can make a Redirect call to an Apps Script?
I answered myself....The issue with this turned out to be that Twilio does not support "chunked" Requests. The error was being caused by Twilio truncating my Request (and thus thinking the XML was not valid due to the perception of missing End Tags) I contacted Twilio support via their support pages and they were able to give me a workaround (they pointed my application to a different proxy server).
Related
First of all, sorry for my bad English :)
I am building a Gmail addon which integrates file uploading to an external website using their API. The API have an auth endpoint which uses plain authorization flow i.e. takes email and password of a user to authorize and return authorization token. That token is then used in the subsequent call of file uploading process.
My question is, it has been mentioned in gmail addon guide that an app should use oAuth when connecting to a third-party service. However, the related website's API do not have oAuth but use plain authorization flow. If I create a login form with email and password fields using the card service, would that be okay and approved by google to be listed in the addons directory? Creating oAuth on third party service is not in my hands
Thank you!
Q: would that be okay and approved?
My experience is that it is OK to use basic authentication (since a lot of APIs still use basic auth, it would be devastating if the use of API was prohibited), most likely you will be approved. However, if there ever be a version of the API that supports OAuth, please, migrate as soon as possible.
Caveats
You mentioned creating a login form in CardService - please, be aware that there are no "password"-style TextInputs, so all characters will be visible all the time + there isn't, as of yet, any support for input event, so you won't be able to emulate the behaviour easily.
If you are planning on storing the credentials, try to avoid using PropertiesService - it isn't considered a secure storage (though if credentials are to be entered only once, storing the token should be fine).
You will still be asked to implement the authorizationCheckFunction.
I have searched StackOverflow, etc. for a solution to this problem, and several answers 'point me in a direction' (mentioning approval_prompt = auto not approval_prompt = force), but none are applicable (as far as I can tell) to my situation.
I have a Web Application hosted at www.mjpanel.com that expects to use a Google Apps Script that I 'own', but the Javascript at www.mjpanel.com calls the Google Apps Script (deployed as a Web App with doGet()) as a Web Service. It expects the web service call to return various JSON objects.
If the user has not yet authorized my application, the call to the Google Apps Script Web App / Web Service will not return a JSON object, causing www.mjpanel.com Javascript code to fail saying "Invalid Request" (because it isn't a JSON object as my code expects).
To prevent this from happening, www.mjpanel.com uses gapi.auth2.init to get the permissions/scopes it needs. I'm developing everything now, so if/whenever the Google Apps Script evolve to use something (like sending GMail emails as the user) that is new, I have been figuring out the scope to request, adding it to the list of scopes in the gapi.auth2.init call, and everything is fine. The next time a user uses the app., they get initially prompted for the newly added scope, then everything proceeds fine.
However, now sometimes one of my test users has a Web Service call fail because Google Apps Script is returning another request for permissions for a 'new permission' of 'Have Offline Access'.
There's nothing about my script that would warrant the user needing to grant this permission.
When I research, a lot of stuff (mostly about requesting OAuth2 stuff in a 'structure' different than the way my app. is set up) says it has to do with submitting a 'approval_prompt=force' in my request URL.
However, the way I have my app set up, all the URLs I would use (aside from my 'custom stuff' in the query string) are dictated by Google Apps Script. And I can't find any place where any URL I use has an approval_prompt in it.
I can't figure out where I would need to configure that approval_prompt to be auto (as is recommended in the 'successful answers' I find).
Of if the idea of approval_prompt is 'on the wrong track', any information in general to help me solve this problem would be greatly appreciated.
Thanks in advance for any help you can give me.
Unfortunately the Google Apps Script native OAuth flow includes approval_prompt=force. This causes the following conditions:
If cookie exists in browser and has permission for this application the consent screen will not be displayed.
If cookie exists in browser but does not have permission for this application: consent screen will be displayed
If cookie does not exist in browser and the application has permissions: application will request 'Have offline access'.
The easiest way around this is to manage your own OAuth flow and use the Execution API. The following link will take you to the javascript quick start.
https://developers.google.com/apps-script/guides/rest/quickstart/target-script
I configured a twilio phone number with sms and set the messaging request url to a twimlets.com/echo url
that returns....
When I send an sms to the twilio number, a "Why" response comes back as expected.
When I change the request url to point to my web-app, which returns output that looks like this...
The inbound sms is logged, but no "Checking.." response comes back to the sms client.
Looking at the inbound log for the number, I see the message was received, but with a warning...
Further inspection finds the body of the response is html indicating a mis-direction somehow.
now, changing the url from https: to http: I see the following.
As you have figured out by now, this webapp is a google apps script web app hosted on google drive... any clue why this link would be failing when called by twilio, but not from my browser?
Thanks for the help Philnash, using incognito mode led me to discover that the problem was that I had published my apps script web app incorrectly.
create a new version of my apps script File > Manage versions
publish the new version (and be sure to select the new version #)
Twilio developer evangelist here.
I just clicked on the link you provided as your application and was met with a page telling me I did not have permission to view the script. My guess is that's the page Twilio is getting right now and why you're able to see the XML but Twilio sees HTML. I'd take a look at the permissions for the script and try to open it up so that Twilio is able to see the page. Checking in a browser in private/incognito mode should help.
In the scenario of scripts that need authentication to run (run as service account, locked down sharing settings, etc) is there a way to authenticate as a Google user via an HTTP tool like cURL, UrlFetchApp, or even PowerShell scripts from Windows Server environments?
You are going to have to do a little leg work on this one.
Firstly, when you publish your apps script, make sure to change the "who has access to the app" to something like "only myself".
Then you need to see what happens when you try to hit that URL from an external service without authenticating. There may be some help from the error codes you are likely to receive.
I imagine you can then use the following documents to Authenticate for Google Services IN GENERAL. Then you will most likely have to pass a sessionID or Accesskey of some sort. I only have a brief understanding of OAuth, but I do imagine that you may be able to set up a more permanent connection between your other server and your particular Google Apps Script.
I hope this helps.
Jacob
I went through the Quickstart on how to upload a file to Google Drive (for Android) and everything works fine. However, it isn't clear whether I am responsible for storing tokens and handling exceptions if they expire. Does the SDK code used in the Quickstart handle this for me behind the scenes?:
https://developers.google.com/drive/quickstart-android
If I regularly call this code (taken from the Quickstart):
credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE);
credential.setSelectedAccountName(accountName);
service = getDriveService(credential);
and then call some drive method, will it eventually generate an exception when the token expires or does the SDK code catch this internally and automatically attempt to retrieve a refreshed token?
To be even more specific, am I required to implement the code shown here:
https://developers.google.com/drive/credentials
What also isn't clear to me is the difference between an access token and refresh token. Then there is "short lived" tokens and "long lived" tokens. Kind of confusing.
On Android, when you use Google Play Services, all of the work is handled for you, including getting the token and refreshing it. This is explained in the quickstart guide that you have linked, and there is nothing more that you need to do.