Custom Scope with ScriptApp.getOAuthToken() - oauth

I have made a custom script to made some calls to the Google Webmaster Tools API.
Now I found the function ScriptApp.getOAuthToken(). So I thought I maybe able to skip the complete custom getting-a-new-token process.
But how can I add a custom scope to the project property scopes, as documented in the Google Webmaster docs?

You don't need to,
In the script editor klik: Resources and then Advanced google services.
Enable the Google Analytics API and klick on the link Google Developers Console to enable the API.
After that you can make API calls without the need of programming oAuth2.0 scopes.
See:
https://developers.google.com/apps-script/advanced/analytics

Related

does google provide a wsdl or wadl

Currently was playing around with a robotic process application called Blue Prism and learned you can drop a URL link to a WSDL location to consume api calls. I tested using a free service and it worked great.
My question is in regards to Google Sheets API, a project has come up where this would be very usefull however I'm not able to locate or if one even exists (A WSDL or WADL) for the google sheets api.
If anyone could give me any direction on this that would be fantastic.
Google docs can be automated using REST web services. You can find more information about google docs api at google sheets API page.
BluePrism has an out-of-box tools to work with SOAP request with WSDL, but unfortunately it does not have out-of-box support for REST web services.
If you'd like to use API to interact with google docs, then you can do that, but you'll have to create your own code stages to do that.

Can we use Google Spreadsheet as a backend database

I am trying to develop an application, where I where fetching data from multiple clients related to some transactions. Now I want to make some analysis using the Google Spreadsheet. Is there any way by which I can achieve this using the ASP.Net MVC(using C#). Google provides OAuth and When I implement the code and when I am trying to send the data to Google spreadsheet which I receive form the clients. However, when I am doing that, for every new client, Google asks for login credential. Client enter their own credentials, and the Google sheet instead a common sheet, client own sheet is used. Thus, my purpose is not solved. Is there any way possible to do this. I does not seem to find proper documentation on Google as well. Please provide some suggestions to implement this. Thanks in advance.
This can be done very easily if you just want a read only database.
You must publish your Google Sheet to the web and, from its url, copy its id.
For example my sheet has this url: https://docs.google.com/spreadsheets/d/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/edit
The long alphanumeric string in the middle is my sheet id. Copy it and place it instead of XXXX in the following url, as follows:
https://spreadsheets.google.com/feeds/list/XXXX/1/public/basic?alt=json"
So the final url would look like this:
https://spreadsheets.google.com/feeds/list/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/1/public/basic?alt=json
Then you can simply access this url and get all your data as json.
Using jQuery:
var $url = 'https://spreadsheets.google.com/feeds/list/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/1/public/basic?alt=json';
$.getJSON($url,function(data){
alert(JSON.stringify(data.feed.entry));
});
You will get a long json structure. The relevant data is in data.feed.entry. There you'll have many entries. On each one you'll have a "content" property and within it, a "$t" one. These will give you all the cells.
So for getting the first row, you will have to get data.feed.entry[0].content.$t.
Hope it helps.
This can be accomplished using Google Apps Script. In particular, you can achieve this with a "bound" script in Google Sheets (i.e. a script that was created in the context of the sheet that you wish to create as the "backend") that you then publish as a "web app" script. When you publish it, you can make it execute with the authority of the owner of the spread sheet (rather than the authority of the user who invokes the url), which will not require the end user to explicitly authorize themselves (since it is the script publisher's credentials, not the user's credentials, that are being used).
It should be noted that, while this (and generally building on top of Google Apps Script) is a reasonable approach for small-to-medium apps, you'll probably find using Google Cloud Platform (and, in this particular case, the Cloud Datastore) as the better, more scalable solution for small-to-large apps. That is, if you are prototyping or creating an internal tool that is unlikely to catch fire overnight, I'd go with whichever approach you find more convenient / simpler; if you are creating an app that could potentially experience a "success disaster", I'd go with Cloud Platform, instead.
If your sheet is public, you can do it withouth authentication. You can use google API Visualization with the query language or use the Google Sheets API.
But if your sheet is private, it is mandatory the use of OAuth2 authentication through service account credentials.
In order to do that, you have to create a service account (with owner of the project role for example). Then you have to download the client_secret.json file which will be the one you use in your code.
Finally you have to share your spreadsheet with the email you get in this file. Look in the file and you will see it.
I have made a tutorial. You can visit at http://edba.xyz/google-sheets-as-database. It is mainly based in PHP but it is easily trasportable to
other languages.
I have recently been developing a website using google sheet as backend. It is great. The speed is also appreciable.
I have integrated the custom backend which I wrote on google apps script with my Django app. So now my website stores the user information on google sheets. The google sheet code and Django app interact via Rest API which can be easily developed using doGet() and doPost() in apps script and python request on the Django side. Once the necessary structure is built( it does take some time tweaking if you are new) but then it works as a great database for your website.
Google spreadsheet is a great solution for quick prototyping database and even in some cases for production use.
People have already realized the potential and there are many tools today for turning your Google spreadsheet into a backend api
There are couple of libraries such as node-sheets for obtaining a json feed from a Google spreadsheet (read-only)
Also, if you need a complete standalone service you have some paid options like
https://sheetsu.com
And also open source options such as
https://github.com/scheduleonce/express-sheets
This can be installed on any cloud provider via Docker and you can point it to your spreadsheet and it will dynamically turn it into an api.
So if, for example, your spreadsheet has the following sheets:
| articles | products | users |
It will automatically create the 3 endpoints
GET /articles
GET /products
GET /users
It is suitable for read-only apis (you update the spreadsheet directly, not through code) that don't need to be changed too often (although you can control the update interval)
You can use Kodem.io.
Google Sheets As Backend allows you to do CRUD requets using Google Sheets.
Disclaimer: I work at Kodem

Accessing Google docs from a chrome extension

I know that the Google Drive API allows for drive integration with Chrome Apps, but what about extensions? Can/How do I use the Drive API in a chrome extension? For example I want an extension that will have a popup that list a user's docs, how do I get access to their drive box?
I know it starts with authentication, but I'm not sure how to do that either.
Regarding authentication, chrome.identity is the place to start.
Taking a (not so) quick look at the GDrive App I didn't really spot any app-specific stuff (i.e. something not available to extensions). So, I would certainly start by trying to "port" the GDrive App to an extension.
There is, also, this tutorial I totally recommend about Building Apps with AngularJS, which actually walks you through building the GDrive App. It is super cool, has a fairly detailed explanation regarding how to set up authentication related stuff (of course, you'll have to slightly adapt that to apply to an extension) and you can just ignore the AngularJS-related stuff (if you are not interested - although AngularJS is super cool too).
Recommended road-map:
Read the docs about chrome.identity, to gain some understanding regarding the API(*).
Study the tutorial, to understand the basic concepts of the GDrive App.
Study the source code of the GDrive App, to get filled in on the implementation details not covered in the tutorial.
Port the GDrive App to a Chrome Extension. (Feel free to come back here on SO if you stumble upon a specific problem during the process.)
[Check out Zig Mandel's answer below for an interesting alternative.]
It's incredibly easy.
chrome.identity.getAuthToken() will handle the authorisation and return an access token. You then use that access token to set an http header when calling the Drive API.
There is some sample code here Chrome Manifest with Google API
Some answers are using chrome identity or the drive api directly. You dont need to use the drive api directly just to get a file-id from a user's drive. If you use chrome identity you have to include the explicit user authorization when they install/upgrade the extension plus the user is giving permissions to the app when it might not be necessary / more risky to the user. Avoid getting/storing tokens when you dont need to. Google has a library called docpicker which does what you need and doesnt require you to deal with authorization nor does it ask authorization to the user. The catch is that you have to download it and possibly adapt it for use from an extension since files need to be all local in an extension.
Ive done it but not for this particular library. Some libraries require that you fiddle with content_security_policy as in:
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
See https://developers.google.com/picker/docs/index for an example.
Update 13/122013 - Google have said that the Picker will shortly be changed to require an oauth token
https://stackoverflow.com/a/58380137/8627279
https://github.com/malik55khan/speardsheet-reader/
Demo: https://www.loom.com/share/d7d432c513a44b05a615fa0bd170fb23
Create a client-auth key in google console and select chrome extension. after that push the project id and save it. then you will get client_id.
Next step create a api key.
add a new project.
- select google cloud or Spreadsheet
- Enable API.
Hope it will be more helpful.

How to submit sitemap.xml using Java to Google Webmaster?

Is there any way to upload/send dynamic sitemap.xml file with updated links to Google Webmaster via its API? It is throwing lot of errors, unable to proceed.
I also tried http://www.google.com/webmasters/tools/ping?sitemap=http%3A%2F%2Fmysite.com%2Fsitemap1.xml, a ping mechanism, but it is not reflecting in Google Webmaster Dashboard after multiple(sitemap2.xml, sitemap3.xml) submits.
So you have followed the below details:
Look at the protocol of submitting a sitemap via the Google Webmaster Tools API.
This is an example of it is down with Java but I would imagine you could use VB, PHP etc to do this also.
Let us know how it goes.

How to programmatically obtain OAuth2 client credentials for Google API

I'm trying to create a redistributable web application that will integrate with Google Analytics through the Google Reporting API. Customer will install the application on their server.
I'm following this tutorial (I'm using PHP, but I believe this is not of importance for my question)
https://developers.google.com/analytics/resources/tutorials/hello-analytics-api
This works fine. No issues there.
However I can't figure out one missing element:
The tutorial starts with sending me to the Google APIs console where I have to create and configure a new API project and create and configure a client ID.
That's a lot of work that requires fairly technical knowledge (redirect url, selecting correct API, error-prone copy-and-pasting, etc.)
So my questions:
Is there an API so I can programmatically set this up for my user?
If that's not possible, is there a more user-friendly way to obtain Analytics reporting that is future-proof? (I noticed they are currently deprecating a few older APIs)
Unfortunately that's AFAIK not possible.
You could go one of the following ways:
Move client_id and client_secret to some configuration file and help your customer with deployment.
Show a one-time setup wizard for your app and guide your customer step-by-step. There you can at least provide him with the right callback URLs.
Regard your application as "installed application" and instrument curl or something similar for sending the requests.

Resources