Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 428
EasilyBaffled Avatar asked Nov 08 '13 19:11

EasilyBaffled


People also ask

Can Google Docs be accessed on any browser?

Access your files from any deviceAfter your files sync, you can access them from any browser or device. Install any web browser. Go to drive.google.com.

How do I open Google Docs in browser instead of app?

Hi there, If you are in Google Drive and you're trying to open a Docs document, simply double-click on it. It should open in a new tab in Chrome. Some additional information (in case you are referring to Google Play/Android, which wasn't clear in your initial question):

How do you enable Google Docs extension for the browser?

Open Google Drive. Settings. Turn on Offline setting. If you are using Microsoft Edge, you will be redirected to the Chrome Web Store to download the Google Docs Offline extension.


2 Answers

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

like image 115
gkalpak Avatar answered Oct 16 '22 22:10

gkalpak


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

like image 4
pinoyyid Avatar answered Oct 17 '22 00:10

pinoyyid