Creating an oauth 1.0a signature for Google Script - google-apps-script

I am trying to connect to an API using an oauth 1.0a signature for Google Script. I am looking for the functions and libraries to use in the Google Script.

Based from this documentation, APIs that act on behalf of a user usually require authorization, often using the OAuth protocol. Apps Script doesn't provide built-in support for the protocol, but there are open source libraries you can use to perform the OAuth flow and send the credentials with your requests.
Check this OAuth1 for Apps Script which is compatible with OAuth 1.0 and 1.0a.
OAuth1 for Apps Script is a library for Google Apps Script that provides the ability to create and authorize OAuth1 tokens. This library uses Apps Script's new StateTokenBuilder and /usercallback endpoint to handle the redirects.
Note: OAuth1 for Google APIs is deprecated and scheduled to be shut down on April 20, 2015. For accessing Google APIs, use the Apps Script OAuth2 library instead.

Related

Can anything done with google apps scripts be done with the google API?

I noticed that the Google Apps Script editor uses a Bearer token to make requests for a lot of things, that got me thinking: Is it possible to do all functions that are done with the google apps script with the google API on your own server? What is the essential difference? Just the fact that google apps script runs on google servers, while with the google API you would need to create your own servers?
For example many of the document functions, which I thought could only be done with the API, turns out can be found here https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertInlineImageRequest
so whats the essential difference?
Just the fact that google apps script runs on google servers, while with the google API you would need to create your own servers?
Yes. There are advantages to both methods:
API:
It's a rest API. You can use your own language(eg: Python) in your servers.
The api is more inclusive. There are stuff which can be done with the api, which cannot be accomplished with apps script.
User can set limited scopes for using API.
For example, at Drive API, https://www.googleapis.com/auth/drive.file can be used for Drive API. The same cannot be done with DriveApp of apps script.
Process cost of API is lower than that of the built-in methods for Google Apps Script1 2
Apps script:
No server on your side
Triggers. You can set up functions to run onEdit,onOpen or at a specific time.
Deep integration with Google apps: Sidebars/modal dialogs can only be done with apps script.
All methods of the api can be accessed indirectly through the bearer token.
Authorization/authentication is taken care of by apps script. You don't need to set up oauth.

JWT for Google Apps Script?

I'm using an API that requires a JSON Web Token generated with a couple of specific and unique parameters. In node, one would simply use var jwt = require(jsonwebtoken') to load the proper library, but that can't be done in Apps Script.
Is there a GAS library that could substitute node's jsonwebtoken module?
On Google Apps Script server side code can "require" code only from other Google Apps Script project. For details see Libraries.
Related Q&A
Is there a complete definition of the Google App Script Syntax somewhere?
Which Edition of ECMA-262 Does Google Apps Script Support?

Use Execution API from App script to App script

I want to use Execution api in app script to call another app script, but I see nowhere some examples to do that.
I've developed the app script api, but I don't know how to make the call in app script.
I need too to have an example to implement the oauth in this script to be able to access the app script api.
Someone can help me ?
Thanks
You may want to check this OAuth2 for Apps Script which is a library for Google Apps Script that provides the ability to create and authorize OAuth2 tokens as well as refresh them when they expire. This library uses Apps Script's new StateTokenBuilder and /usercallback endpoint to handle the redirects.

Access Adwords through GAS

I want to manage my Adwords campaigns through a script. I have a few Adwords scripts running and this is all fine, but now I need to access a library. Unfortunately this is not possible from the Adwords script interface so I need to access my Adwords MCC from the "normal" scripts interface.
Through resources - advanced google services , I don't come across a Google Adwords API. Any ideas on how to do this?
Thanks!
Turns out this is not (yet) supported.
Source: https://groups.google.com/forum/#!topic/adwords-scripts/G2GiGMp5Ols
Unfornately, AdWords is not available in Advanced Google Services. But you can try communicating using External APIs.
var url = 'https://gdata.youtube.com/feeds/api/videos?'
+ 'q=skateboarding+dog'
+ '&start-index=21'
+ '&max-results=10'
+ '&v=2';
var response = UrlFetchApp.fetch(url);
Logger.log(response);
Making requests to services with OAuth
APIs that act on behalf of a user usually require authorization, often using the OAuth protocol. Apps Script doesn't provide built-in support for the protocol, but there are open source libraries you can use to perform the OAuth flow and send the credentials with your requests:
OAuth1 for Apps Script: Compatible with OAuth 1.0 and 1.0a.
OAuth2 for Apps Script: Compatible with OAuth2.
Hope this helps.

Buying more quota in GCP for Google Apps Script quota

I'm facing quota limits of sending mails via Google Apps Script. The limit is 100 a day. I called the support center, but they say the script is out of the scope of Google Apps Service.
They told me I could buy more quota at GCP (Google Cloud Platform), now my question: Do I have to code new scripts on the GCP, or can I somehow connect the Google Apps Script (which is part of Drive and Apps I guess) with GCP?
I'm not sure if you can link both projects, however, I think Apps script email service would still be limited by it's own quotas.
A possible workaround would be to call the Gmail API directly instead of using the Apps script Gmailapp service.
To call the API you can use the "UrlFetchApp.fetch()" to make the call to the Gmail send endpoint.
To be able to make the call to the Gmail API, you will have to enable it in the developer console, for this in your script go to "Resources -> Advanced Google Services". There you will enable the Gmail API, then you have to click on the link that says "These services must also be enabled in the Google Developers Console."
It will take you to the Developer Console of your Appscript project, there you also have to enable the Gmail API.
The quota for UrlFetch is 20k calls/day, so in this case you would be limited by this quota and the Gmail API quota.