Accessing Google docs from a chrome extension

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:

  1. Read the docs about chrome.identity, to gain some understanding regarding the API(*).
  2. Study the tutorial, to understand the basic concepts of the GDrive App.
  3. Study the source code of the GDrive App, to get filled in on the implementation details not covered in the tutorial.
  4. 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