mohamedmansour / google-plus-extension-jsapi

Unofficial Google+ Read/Write Extension API
https://plus.google.com/116805285176805120365/posts/JYiVWmFbeSn
Other
175 stars 35 forks source link

An Unofficial Google+ JavaScript API

It has been 6 months since we have seen any Circle/Posts/Followers Write/Read API for Google+. Since Google+ is by nature asynchronous we could tap into their XHR calls and imitate the requests.

Who uses this API:

My Hangouts Chrome Extension https://plus.google.com/116935358560979346551/about

Circle Management Chrome Extension https://plus.google.com/100283465826629314254/about

Map My Circles for Google+™ https://chrome.google.com/webstore/detail/mcfifkeppchbjlepfbepfhjpkhfalcoa

Nuke Comments on Google+ https://chrome.google.com/webstore/detail/nfgaadooldinkdjpjbnbgnoaepmajdfh

Do Share on Google+ https://chrome.google.com/webstore/detail/oglhhmnmdocfhmhlekfdecokagmbchnf

Who made this:

Core Contributors

Contributors

What is it about:

I provide you a very basic asynchronous Google+ API, in the current release, you can do the following:

This is a fully read and write API.

Native Examples:

// Create an instance of the API.
var plus = new GooglePlusAPI();

// Initialize the API so we could get a new session if it exists we reuse it.
plus.init();

// Refresh your circle information.
plus.refreshCircles(function() {

   // Let us see who added me to their circle.
   plus.getPeopleWhoAddedMe(function(people) {
     console.log(people);
   });

   // Let us see who is in my circles.
   plus.getPeopleInMyCircles(function(people) {
     console.log(people);
   });

   // Let us see who is in our circles but didn't add us to theirs.
   plus.getDatabase().getPersonEntity().find({in_my_circle: 'Y', added_me: 'N'}, function(people) {
     console.log(people);
   });
});

As you see, it is pretty easy to query everything. The possibilities are inifinite since the data is backed up in a WebSQL DataStore, so querying, reporting, etc, would be super quick.

If you want to place that in an extension, I have created a bridge, so you can use this in a content script context and extension context safely. To do so, you send a message as follows:

// Initialize the API so we get the authorization token.
chrome.extension.sendRequest({method: 'PlusAPI', data: {service: 'Plus', method: 'init'}}, function(initResponse) {
  chrome.extension.sendRequest({method: 'PlusAPI', data: {service: 'Plus', method: 'refreshCircles'}}, function() {
    // etc ... The method is the same method we defined previously in the raw example.
  });
});

Another example, lets say we want to search for a hash tag:

// Initialize the Google Plus API Wrapper.
var api = new GooglePlusAPI();

// Lets initialize it so we can get the current logged in users session.
api.init();

// Search for the API. You have the following enums to choose from for searching:
//
//   GooglePlusAPI.SearchType.EVERYTHING
//   GooglePlusAPI.SearchType.PEOPLE_PAGES;
//   GooglePlusAPI.SearchType.POSTS
//   GooglePlusAPI.SearchType.SPARKS
//   GooglePlusAPI.SearchType.HANGOUTS
//   GooglePlusAPI.SearchType.HASHTAGS
//
// So lets search for hashtags that have Microsoft inside them.
api.search(function(resp) {
  console.log("Hash results for Microsoft: " + resp.data.join(", "));
}, "microsoft", { type: GooglePlusAPI.SearchType.HASHTAGS });

A full blown example will be released by the end of this week showing how powerful this could be. As you already know, I am creating a simple circle management utility so you can manage your circles.

API Documentation

AbstractEntity Members:

PlusDB Entities:

Native querying:

Initialization, fill up the database:

Persistence:

Read:

Private Members (only for internal API):

Watch this space!