how to distinguish a free user from a paid one - freemium app in chrome web store

388 views Asked by At

those are the actions I've done so far: i've got myself a new project in developers console here: https://console.developers.google.com/project/

and enable those api's: * Chrome Web Store API

  • Google+ API
  • BigQuery API
  • Debuglet Controller API
  • Google Cloud SQL
  • Google Cloud Storage
  • Google Cloud Storage JSON API

my guess is I don't really need all of them . . .

in "credentials" under APIs and auth I have "Client ID for Chrome application".

I took the "client ID" and planted it in my manifest.json file like this:

"oauth2": {
        "client_id": "blablablabla.apps.googleusercontent.com",
        "scopes": [
          "https://www.googleapis.com/auth/drive"
        ]
    }

also those are my chrome extension permissions in the manifest.json:

"permissions": [
        "http://*/*",
        "https://*/*",
        "tabs",
        "cookies",
        "management",
        "notifications",
        "contextMenus",
        "management",
        "storage",
        "webRequest",
        "webRequestBlocking",
        "identity"
    ],

i've got myself a new project in developers console here: https://code.google.com/apis/console don't know if I needed to . . .

when i'm trying to do this request:

chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
            var CWS_LICENSE_API_URL = 'https://www.googleapis.com/chromewebstore/v1.1/userlicenses/';
            var req = new XMLHttpRequest();
            req.open('GET', CWS_LICENSE_API_URL + chrome.runtime.id);
            req.setRequestHeader('Authorization', 'Bearer ' + token);
            req.onreadystatechange = function() {
              if (req.readyState == 4) {
                var license = JSON.parse(req.responseText);
                if (license.accessLevel == "FULL") {
                    // paid
                }
                else {
                    // free
                }
              }
            }
            req.send();
        });

i'm getting a 403 (Forbidden) error - "Insufficient Permission".

Just to be clear the getAuthToken request doe's provide me with the token.

all I want is to distinguish a free user from a paid one. way is that so hard :(

1

There are 1 answers

0
sdolphin On

Not that this answer is timely but you need to include an additional scope that allows you to get the api result.

The scope required for that request is: "https://www.googleapis.com/auth/chromewebstore.readonly"

You can read more on how to authorize and use that api call at: https://developer.chrome.com/webstore/webstore_api/userLicenses/getUserLicense