possible to set "anyone with the link" permissions using the java client?

333 views
Skip to first unread message

Dan Foygel

unread,
Mar 7, 2011, 2:21:32 PM3/7/11
to google-docum...@googlegroups.com
We're trying to set "anyone with the link" can edit permissions on a document using the java client apis.

The latest information I've seen on the forums suggests that this isn't yet supported (http://www.google.com/support/forum/p/apps-apis/thread?tid=3ab6ec83b0690bbf&hl=en) - is that still the case? 

Assuming that's the case, we've written some code that accomplishes this with a small bit of raw XML (although we would of course prefer to use supported client code).  Here is a snippet of code:

  private void demo(com.google.gdata.client.Service service, com.google.gdata.data.docs.DocumentEntry doc) throws IOException, ServiceException {
    XmlBlob blob = new XmlBlob();
    // the suggested key is ignored - google generates their own which we then retrieve
    blob.setBlob("<gAcl:withKey key='whatever'><gAcl:role value='" + AclRole.WRITER.getValue() + "' /></gAcl:withKey>");
    blob.addNamespace(new XmlNamespace("", "http://www.w3.org/2005/Atom"));
    blob.addNamespace(new XmlNamespace("gAcl", "http://schemas.google.com/acl/2007"));

    AclEntry aclEntry = new AclEntry();
    aclEntry.setScope(new AclScope(AclScope.Type.DEFAULT, null));
    aclEntry.setXmlBlob(blob);
    service.insert(new URL(doc.getAclFeedLink().getHref()), aclEntry);
  }

Are there any problems or potential pitfalls associated with doing this?  It feels like a relatively robust solution, since we're using published APIs, just without native client support.  Should we be concerned that this implementation might break if Google updates to a new version?

Thanks,

-Dan

Vic Fryzel

unread,
Mar 8, 2011, 1:58:09 PM3/8/11
to google-docum...@googlegroups.com, Dan Foygel
It's not currently possible to set an ACL key via the API, because the key must be generated by Google Docs.  I'm looking into adding this feature, but have no ETA yet.

Thanks,
-Vic

Dan Foygel

unread,
Mar 8, 2011, 2:21:36 PM3/8/11
to google-docum...@googlegroups.com, Dan Foygel
Thanks for the reply, Vic.

I was unclear in my original question.  We'd like to set "any with the link" permissions on a document - and I understand that's accomplished by associating a key with the document.  We do not care if the actual key is generated by us or by Google - either way is completely fine.

It appears that there is no way to currently set do that using the high-level methods in the java client libraries.  The code that I provided above (which uses a little raw xml) does work - I was perhaps not clear about this.  After running that snippet of code, we are then able to retrieve the key generated by Google (using similar raw xml processing) and then we generate the document URL with a ?authkey=XXX parameter, which allows the user to access the document.

So everything is working end-to-end.  My question is this - are we performing an unsupported operation, with a risk that it may break at any point in the future?  Or are we doing something that's supported and intended to work, but simply not yet implemented by the java client libraries?  I realize that's a somewhat odd question to ask, but the documentation for this functionality is pretty sparse.

Thanks,

-Dan

Vic Fryzel

unread,
Mar 8, 2011, 2:33:09 PM3/8/11
to google-docum...@googlegroups.com, Dan Foygel
I was also unclear.  I understand your question, but regardless of who generates the key, this isn't currently possible with the API.

-Vic

VHanded

unread,
Mar 31, 2011, 2:27:25 AM3/31/11
to google-docum...@googlegroups.com, Dan Foygel
Hi, can I know how you obtain the authKey? I had been trying for days, no luck.

Thanks.

Vic Fryzel

unread,
Mar 31, 2011, 10:59:49 AM3/31/11
to google-docum...@googlegroups.com, VHanded, Dan Foygel
You found a gap in our Java client lib.  I'll see about getting key support added asap.

-Vic

Vic Fryzel

unread,
Mar 31, 2011, 11:31:00 AM3/31/11
to google-docum...@googlegroups.com, VHanded, Dan Foygel
We're about to push an updated version of the Java client that will have this functionality.  Looking into the .NET client...

-Vic

Guillaume Leseur

unread,
Apr 5, 2011, 5:33:13 AM4/5/11
to google-docum...@googlegroups.com, Dan Foygel
Hi, 
As I understand Dan's reply, it is actually possible to set "anyone with the link" (as he says he does it) and then get the new key back with the API.
I'd also like to do that and therefore would like to know if this is a supported feature of the API of just a trick that may stop working.
If the feature is actually supported, is it possible to ask for the key to be reset.
If this is not supported, do you plan on supporting it someday.

My question is not client related but API related.
Thanks

Vic Fryzel

unread,
Apr 5, 2011, 4:46:31 PM4/5/11
to google-docum...@googlegroups.com, Guillaume Leseur, Dan Foygel
Hi,

Two points:

1. We don't currently support the ability to set or change the key, that I'm aware of.  The API is readonly in this regard.  We've taken a feature request for this though, and are considering adding it.

2. The update do the Java client we're pushing will allow you to read these keys from Java.

Thanks,
-Vic
Message has been deleted

M. FarouQ

unread,
Apr 25, 2011, 5:46:32 PM4/25/11
to google-docum...@googlegroups.com, VHanded, Dan Foygel
I'm bumping this thread because I want to read the key which the protocol documentation "claims" to be retrievalbe from the DocumentListEntry only there's no way to do that.

Basically I want to achieve the following:
AclEntry aclEntry = new AclEntry();
AclRole role = new AclRole("writer");
String key = ?????????????????????????????
AclWithKey withKey = new AclWithKey(key, role);
aclEntry.setWithKey(withKey);
service.insert(aclFeedUrl, aclEntry);

So how or where can I get the authkey which is supposed to be appended to the "alternate" link to produce the public share URL. 
Please advise. Thanks.

Message has been deleted

M. FarouQ

unread,
Apr 25, 2011, 8:05:52 PM4/25/11
to google-docum...@googlegroups.com, VHanded, Dan Foygel
To clarify on the issue, suppose the current visibility selection is "Public on the web" and the user changes his selection to "Anyone with the link", my question is : how can I use the Java API to "update" the aclEntry with scope "DEFAULT" using setWithKey when I can't get the authKey which probably hasn't been generated yet because it is supposed to be assigned by Google?

The same goes for "DOMAIN" scope selection being changed to "DOMAIN" with link. How can I get the authKey to update the aclEntry in this use case? 

Ivan Lee

unread,
Apr 26, 2011, 2:52:20 PM4/26/11
to google-docum...@googlegroups.com, VHanded, Dan Foygel
I believe if you set any value for the key, it will be discarded and the appropriate key will be set (and outputted in the response).

M. FarouQ

unread,
Apr 26, 2011, 5:39:15 PM4/26/11
to google-docum...@googlegroups.com, VHanded, Dan Foygel
I thought so as well since Dan (guy who started this thread) used a similar method using XMLBlobs but this is the code I used and this is the exception I got: 

This code is supposed to update the public default sharing "Public on the web" to "Anyone with the link". ... I think
aclEntryUrl = new URL("https://docs.google.com/feeds/default/private/full/"+resourceID+"/acl/default");

AclEntry aclEntry = service.getEntry(aclEntryUrl, AclEntry.class);
aclEntry.setScope(new AclScope(AclScope.Type.DEFAULT, null));
String authKey = "whatever";
AclWithKey withKey = new AclWithKey(authKey, new AclRole("reader"));
aclEntry.setWithKey(withKey);
aclEntry.update();


com.google.gdata.util.InvalidEntryException: 
The posted entry has an invalid value for the field(s): role withKey
<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>InvalidEntryException</code><internalReason>The posted entry has an invalid value for the field(s): role withKey</internalReason></error></errors>

Ivan Lee

unread,
Apr 26, 2011, 5:45:31 PM4/26/11
to google-docum...@googlegroups.com
Is your URL correct?  Particularly, should the "/default" part be at the end there?

M. FarouQ

unread,
Apr 27, 2011, 4:26:18 AM4/27/11
to google-docum...@googlegroups.com
This URL is the aclEntry's edit link. entry.getEditLink() and "default" is used to denote "Public on the internet" files, this is similar to sharing with an entire "domain" in which case the URL would've been:

/feeds/default/private/full/document%3Adocument_id/acl/domain%3Aexample.com

Also, I think the exception would have been very different had it been a faulty URL. The exception I'm getting (see previous post) has to do with the "withKey" tag. Is it known for a fact (i.e. someone has tried it before) that setting a bogus value for the authKey gets amended by Google later on? 

Ivan Lee

unread,
Apr 27, 2011, 12:51:19 PM4/27/11
to google-docum...@googlegroups.com
I was able to do it with:

DoclistService service = ...;
AclEntry entry = new AclEntry();
entry.setScope(new AclScope(AclScopeType.DEFAULT, null));
AclWithKey withKey = new AclWithKey("blah", new AclRole("reader"));
entry.setWithKey(withKey);
URL url = new URL(https://docs.google.com/feeds/default/private/full/" + resourceId + "/acl");
service.insert(url, entry);

The difference may be you were trying to modify an ACL and this one just adds one granting permission.

M. FarouQ

unread,
Apr 27, 2011, 9:59:18 PM4/27/11
to google-docum...@googlegroups.com
Ivan, thanks for bearing with me. But I tried the above code and got the following exception:

com.google.gdata.util.VersionConflictException: This user already has access to the document.
<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>ServiceException</code><internalReason>This user already has access to the document.</internalReason></error></errors>

Any clue as to what's causing this? BTW I'm using the latest Java client 1.45

Ivan Lee

unread,
Apr 27, 2011, 11:54:40 PM4/27/11
to google-docum...@googlegroups.com
Does that document already have an "Anyone with link can..." AclEntry on it?  If so, can you try calling "service.update(url, entry)" instead?

M. FarouQ

unread,
May 1, 2011, 9:46:52 AM5/1/11
to google-docum...@googlegroups.com
Ivan, I finally figured it out. It wasn't the service.update because that just brought me back to the original InvalidEntryException exception.
Basically I needed to treat an update from a normal "public" or "domain" scope setting to one "with link" as a new aclEntry (as your code suggested) but I had to DELETE the current scope FIRST like so:

scope = new AclScope(AclScope.Type.DEFAULT, null);
service.delete(aclFeedUrl, scope);

AclEntry aclEntry = new AclEntry();
aclEntry.setScope(scope);
AclWithKey withKey = new AclWithKey("gspot", role);
aclEntry.setWithKey(withKey);
service.insert(aclFeedUrl, aclEntry); 

and that seemed to work. Thank you for your help, appreciate it.



Reply all
Reply to author
Forward
0 new messages