Search code examples
oauthgoogle-chrome-extensiongoogle-drive-apigoogle-chrome-app

Accessing Google docs from a chrome extension


I know that the Google Drive API allows for drive integration with Chrome Apps, but what about extensions? Can/How do I use the Drive API in a chrome extension? For example I want an extension that will have a popup that list a user's docs, how do I get access to their drive box? I know it starts with authentication, but I'm not sure how to do that either.


Solution

  • 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.]