I'm writting a script in Google Aps (GAS) and I need to add a user(/writer) (administrator of the domain) to a spreadsheed of a another user.
The script is running/invoked under administrator privilegies.
First I use "Google Apps administrative access to impersonate a user of the domain" and I get a list of his documents (spreadsheets) and I get the Id of the documents.
var oauthConfig = UrlFetchApp.addOAuthService("docs"); oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken? (...)
This part is working fine and get the desired Id's.
Now, I want to add to myself (administrator@example.com) to this document
I'm trying this:
var optAdvancedArgs = {
"contentType": "application/atom+xml",
"method": "POST",
"headers": { "GData-Version": "3.0" },
"oAuthServiceName": "docs",
"oAuthUseToken": "always",
};
var url_set = "https://docs.google.com/feeds/" + user + "/private/full/document:" + matriu2[0][6] + '/acl/user:administrator@example.com'
var result = UrlFetchApp.fetch(url_set, optAdvancedArgs);
"user" is the owner of the document, the active user (Session.getActiveUser().getUserLoginId()) and "matriu2[nm][6]" is the Id of the document.
This don't work,
Any ideas ?
Sergi
I would never have found this. Thank you very much.
I modified the following (var url = ...):
by
user + '/private/full/'
where
and also in the
googleOAuth_
I put my domain values:And it works perfectly!
I think it's very interesting that administrator of a domain can act on behalf of a user (once we have given permission) with some of the documents of the organization but have been created by the user.
Also user resources (docs, spreadsheet, ...) so that a program can access (running with administrator permissions) without requiring the attention (or you do not have enough expertise) of the user, such as copies of security, ...
In my case, I make a program to evaluate a Google Docs form has been created by a user (a teacher) as does the gadget "Flubaroo" but in a graphical environment (GUI) programmed by Google Sites with Google Apps Script (GAS).
Thanks again for your time.
Sergi
After spending an hour of time, here is what I got This function will share the document to yourself (Domain administrator). You may change other parameters in xml to have read, write permission etc
I have posetd the same code on my Google Site. You can have a look here. https://sites.google.com/site/appsscripttutorial/urlfetch-and-oauth