No Google Drive API writersCanInvite equivalent? - permissions

With Docs API deprecated and some nice new functionality in Drive API, I'm working on updating some of my file migration scripts. However, I've found there doesn't seem to be a Drive API equivalent to the writersCanInvite parameter in Docs API v3. Being able to set this attribute on a file would be extremely important during migration scenarios as without it, the migrated file would be left open to having editors share it out further.
Not having writersCanInvite avaialble in addition to not being able to see email addresses (or some Unique ID) for the ACLs is preventing me from fully porting over my migration script to Drive API v2.
Thanks Guys,
Jay

It looks like we now have a writersCanShare attribute that controls this:
https://developers.google.com/drive/v2/reference/files#resource
at the moment, it's not marked as writeable but I had no problems making it False for a new document so I'm guessing that's just a documenation issue.

Related

Does Google Data Studio have API functionality, and if not, will it in the near future?

I'm trying to automate a workflow using Google Data Studio. Requirements are simple - I need to be able to programatically copy a templated report (from a Python/Java application) and import/set a data source (Google Sheets doc) for that report. Nothing more fancy (no visualisation creation, formatting, or anything graphical, etc.).
Sources here, here and here (last two require Google Cloud Console account) suggest an API does exist (and detail a setup process to access it). However, after going through this setup process, I can find no details or documentation of any functionality, and consequently have been unable to progress.
Can anyone authoritatively state whether:
1. There does exist any API functionality for GDS? and
2. If not, are there plans to develop such? (since the Google links above suggest there is, I'm wondering if this means it's in the pipeline for near future).
The only directly related SO posts I can find are here and here. The first suggests there isn't, but doesn't account for the Google links I've provided above which suggest there is; the second doesn't really cover the same use case, so doesn't provide answers applicable here.
FYI - I've posted a Google Community forum post here asking essentially the same question.
If anyone is able to help out, that would be greatly appreciated :) Many thanks in advance for your time and help! :)
Fresh as of 2022-05-23
There does exist any API functionality for GDS?
Not in the way you are expecting. The three links you posted all refer to the current Data Studio API. The only things you can do with that API is view your Data Studio assets and update permissions. That's it. This API won't let you create/copy/modify reports or data sources.
If not, are there plans to develop such?
Not in the near future. You can make/vote for this feature request in the official tracker. More popular feature requests are usually prioritized in roadmaps.
That being said, a lot of the API use cases can be resolved using combinations of Community Connectors, config parameters, direct linking, viewer's credentials, Linking/Integration API etc.

Migration from Google Drive API v2 to v3

Recently I've taken the time to migrate a VB.NET project that used google drive apis v2 to the v3 instead. I got the basic things to work but there are some details about storage usage and some other simple safety validations that I did that now don't work. It's quite silly actually, but I don't know how to get this to work, here's the thing:
In v2 I used this line - service.About.Get().Execute.User.EmailAddress - to get the email address that the token was created with, and then compared it to the one that the user was actually trying to upload files to, and see if they matched.
The problem is that I can't make that line work anymore, I've read in another question here in SO Google Drive API v3 Migration that this:
service.about().get().setFields("user, storageQuota").execute()
should be the new way of doing this kind of thing, but visual studio says there's not such method like "setFields" there.
Does anyone know what am I doing wrong or what is the correct way of doing this in VB.NET? Thanks.

Is there to read the data from google spreadsheet link in IOS?

i am currently work on an IOS project which is required to read data from Spreadsheet in google drive. I have done some research and i found Google APIs client library for Objective C. However, i still have problem of retrieving data from spreadsheet. i find only the sample code that can read the file in drive from the drive that user login. But what i actually want in this project is using Google Drive as the Database. In short i want to retrieve data from the url like this https://docs.google.com/spreadsheet/ccc?key=0AoYC7S60-ywcdHVZYzh4ZlZ1Y3J5R2ZGbnBqY09jdkE&usp=sharing.
So is there a solution for this kind of problem? and if there a good site that provide a good tutorial to this kindda problem?
Google apps script is probably a simpler option. You can set it up as a web app, and read/write to the spreadsheet via the webapp. The google-spreadsheet-api is hard to use as there is little good documentation.
Refer, Google's Sample Code it can help you. You can also use GData Objective C Client to use it.

Can you create Google Forms from Google Docs in an application?

I am thinking about app that will use google form and I need to create forms from that app. Is there a way how can I create form in google docs without using website but through some api or some other way?
I can offer an idea for a solution using Google App Script.
Since the beginning of 2013 you can create new forms using the App Script Forms Service API quite easily.
var form = FormApp.create(title)
.setDescription(description)
.setConfirmationMessage('Thanks for responding!')
;
The problem now is how to get that App Script running from your non App Script code.
You can use App Script to create a Web App that reacts to HTTP GET requests.
So putting it together, you may be able to create an App Script Web App that reacts to a GET request and when it gets the right URL parameters, it creates the form.
(Nov 2020) Yes, it is possible to programmatically create Google Forms. You can do it with Google Apps Script using its Forms service. You can also extend the code to read in the contents from Google Docs (with Apps Script's Document service) and use it for the creation of Google Forms.
I created a Google Workspace (formerly G Suite) Add-on, which you can think of as a Google Docs extension, called GFormIt. Its original purpose was intended for teachers to write exams/quizzes, possibly with answers, in Google Docs, then automatically convert them to Google Forms to distribute to students who submit their answers into Google Sheets (the destination for Google Forms submissions).
Furthermore, if you (the teacher) provided answers to your test questions, GFormIt would also auto-submit your answers to the Sheet as if you were a student. If you do that, and use a tool like Flubaroo to grade the exam, you could designate your row in the Sheet as “the answer key.” You can learn more about how it works, including viewing a short video, at the GFormIt page linked above.
This Google Docs add-on, along with others for Google Docs, Sheets, Slides, Forms, etc., are all certified/validated by Google and available for free to anyone from the Google Workspace Marketplace. (However, your admins may have to grant permissions for you to try to install them to your corporate Workspace account.) If interested in building your own add-on, please see the developer documentation and perhaps some of my introductory videos to get started, the most relevant being the one linked to at the top of this answer.
Apps Script is a serverless Google technology, meaning you write your code (using JavaScript) in the browser, and it is hosted by & executed on Google servers. If you wanted to create your own web app (and hosted anywhere), you would have to wait for a Google Forms REST API which does not exist at the time of this writing. (If we ever launch one, you'll find its documentation at https://developers.google.com/forms along with the others like Sheets https://developers.google.com/sheets, Gmail https://developers.google.com/gmail, Drive https://developers.google.com/drive, etc.)
Earlier this year (Mar 2022) the new Google Forms Api graduated from Beta. It is more powerful that the previous versions and caters for two main use cases:
Automated form creation and editing: Enables automated form creation
and editing. Enables rapid form generation from large volume question
banks or other data backends.
Reaction to Form responses: The API also enables developers to build
automations for acting on incoming responses. Examples include
developing real-time dashboards or visualizations and triggering
business workflows based on response data.
We have used it to build an integration that Creates documents and slides each time a form is completed: www.portant.co/google-forms-to-docs and it works really well.
I think the other key use case looks like it would be a good fit for you and others looking for a solution like this.
Cheers, James
Sorry, the API doesn't support programmatically creating forms.

How do you create a document in Google Docs programmatically?

The documentation for Google Documents List API, seems to say that you can create a local document and upload it. Is there no way to actually create and edit a document on Google Docs through an API?
While the docs call it "uploading", everything boils down to sending an appropriately formatted HTTP POST request, so of course it can actually be a new creation rather than an actual "upload" of an otherwise existing file. (Creation through POST requests is similar to what's normally described as a REST API, though in real REST you'd typically use a PUT request instead of course).
You just need to create a blob of data representing your document in any of the formats listed here -- depending on your programming language, simplest may be text/csv for a spreadsheet and application/rtf for a text-document -- then put in in an appropriately formatted POST data. For example, to make a spreadsheet in the simplest way (no metadata), you could POST something like:
POST /feeds/default/private/full HTTP/1.1
Host: docs.google.com
GData-Version: 3.0
Authorization: <your authorization header here>
Content-Length: 81047
Content-Type: text/csv
Slug: Example Spreadsheet
ColumnA, ColumnB
23, 45
Each specific programming language for which a dedicated API is supplied may offer help with this not-so-hard task; for example, in Python, per the docs, the API recommends using ETags to avoid overwriting changes when multiple clients are simultaneously "uploading" (i.e., creating or updating docs). But preparing the POST directly is always possible, since the almost-REST API is documented as the protocol underlying all language-specific APIs.
Alex's answer, while undoubtedly correct, begs the question: "how do I do that via the Google Docs API?"
Here's a way (in Python, 'cause I'm that kind of guy):
import gdata.docs.service
import StringIO
client = gdata.docs.service.DocsService()
client.ClientLogin(username, password,
source='Spreadsheet Creation Example')
content = 'COL_A, COL_B, COL_C, COL_D\ndata1, data2, data3, data4'
ms = gdata.MediaSource(file_handle=StringIO.StringIO(content),
content_type='text/csv',
content_length=len(content))
entry = client.Upload(ms, 'Test Spreadsheet')
This is a small mashup of techniques that I found in http://code.google.com/p/gdata-python-client/source/browse/tests/gdata_tests/docs/service_test.py , which I in turn found via this post from the Google Group for the GData Docs API.
The key insights (for me anyway) were:
realizing that the MediaSource constructor's formal parameter "file_handle" will take any file-like object, and
discovering (as the OP's followup to the Google Group post mentions) that the unit tests are a great source of examples
(I wasn't able to find the Python-specific developer's guide referenced by Alex's doc link -- possibly it's been lost or buried in Google's move of documentation assets from code.google.com to developers.google.com. Alex's link now redirects to the more generic document that shows mostly .NET and Java examples, but only a little Python.)
As of Feb 4, 2019, Google Docs now has a REST API.
See documentation:
https://developers.google.com/docs/api/
(Sep 2019) There are 3 ways to create a document in Google Docs programmatically:
Google Docs REST API (low-level; Python, JS/Node.js, Java, C#/.NET, PHP, Ruby, Go, etc.)
Google Apps Script (high-level; JavaScript-only)
Google Drive API (low-level like Docs API above; both alternatives above can create or edit documents, but this one is create- or delete-only plus editing sharing/permissions)
The Docs API was officially launched in Feb 2019. I produced a high-level video overview of what a mail merge application using the API would look like. (It's not a full-fledged G Suite Dev Show episode but does link to a working sample.) Check out the various guides on using the API, including Quickstart examples in a variety of programming languages.
OTOH, Apps Script is a simpler, higher-level alternative. It's a custom server-side JavaScript runtime supporting apps that are hosted+executed in Google's cloud. Use objects to talk to various Google APIs (G Suite & beyond) without knowledge of HTTP, REST, nor OAuth2. You can also access external databases with its JDBC Service or call other apps via its URL Fetch Service.
With Apps Script, you can create standalone applications, document-bound applications (only works for a single document), or Google Docs Add-ons to extend the functionality of Google Docs. Here are the Google Docs Apps Script overview page as well as the Apps Script reference documentation for Google Docs (Document Service). I've also produced a variety of Apps Script videos if that's your preferred learning vehicle. If you're new to Apps Script, see my answer to a similar SO question for more learning resources.
Typically the Docs, Sheets, Slides, etc., APIs are used to perform document-oriented functionality while the Drive API is used primarily for file-based operations. However "create" is a special case where you can use either. See my answer to another SO question which shows the difference b/w creating a new Google Sheet via the Sheets API vs. the Drive API. (Both samples in Python.) Read this if you're interested in managing sharing or updating permissions of Google Docs.