Sharing file in Google Drive with public

google-drive-api

Using the Google Drive web interface, I right click on a file, select 'sharing', to get to "Sharing Settings." I set the file to "Public on the web – Anyone on the Internet can find and view."

I then copy the "link to share", in this case it is:
https://docs.google.com/open?id=0B6Cpn8NXwgGPbFBPMEh5VHc1cUU

I then click "Done."

If I open another browser, no cookies, and try to visit the link, I am redirected to sign-in page for Google. I assumed this setting meant that no authentication would be required to view the file. Is this the expected behavior?

I am trying to do the same thing through the API, and I am not getting the expected result either when setting the permissions to public, setting 'anyone' as 'reader,' and using the webContentLink value for the file as the published URL. Also in this case, if I go to the link when not signed in to Google Apps, I am redirected to sign-in.

I call the following method to set permissions using this:

thePermission = insert_permission(userNickName,file['id'],"me","anyone","reader")

the method:

def insert_permission(userNickName,file_id, value, perm_type, role):

  credentials = get_stored_credentials(userNickName)
  service = CreateDrive(credentials)
  if service is None:
      return

  """Insert a new permission.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to insert permission for.
    value: User or group e-mail address, domain name or None for 'default'
           type.
    perm_type: The value 'user', 'group', 'domain' or 'default'.
    role: The value 'owner', 'writer' or 'reader'.
  Returns:
    The inserted permission if successful, None otherwise.
  """
  new_permission = {
      'value': value,
      'type': perm_type,
      'role': role
  }
  try:
    return service.permissions().insert(
        fileId=file_id, body=new_permission).execute()
  except errors.HttpError, error:
     print 'An error occurred: %s' % error
  return None

I am asking about the UI interface primarily in this question, as it seems simpler to find out if I am expecting the correct result using what Google has made.

Best Answer

I finally found the problem in my case. My GAE app was using "Federated Login" for "Authentication Options", instead of "Google Accounts API". Everything worked with Google Drive API. I am able to put files, delete, move, you name it, with the Oauth login. But for some time now, I have been unable to share files publicly from Google Drive that were created from my GAE app. I was always prompted to login if trying to view these files without being logged in to Google Apps.

I decided to drop Oauth login for GAE and go with Google Accounts logins since everyone using the app will now need Google Drive. After switching the GAE app in the dashboard from "Federated" to "Google Accounts", I can happily share files to the public without any login required.

So it appears that Google Drive does not yet fully support "Federated Login" at GAE, which is hardly anything to complain about since "Federated Login" is shown to be experimental.

Related Topic