Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

Commit

Permalink
4.x (#45)
Browse files Browse the repository at this point in the history
* breaking changes, new device user agents

- default to nexus 5X device profile
- update README to include info regarding getting appropriate user
  agents
- update README to incldue info about getting the device id
- breaking change to API options

* Fix download user agent png

* Clean up

* var => const cleanup

* Add support for download of an additional file required for install

* Use semistandard for linting/format check

* Switch to tap for tests

* Tweak addl file getter

- add skipped test (need to update travis device profile)

* Bump proto ver

* Update travis env to use new login, device id

* Enable addl. file info test

* Make linter happy

* Fix get-latest-proto lint

* Fix test transition to node tap
  • Loading branch information
dweinstein authored Aug 21, 2016
1 parent 8ed6158 commit 82c0550
Show file tree
Hide file tree
Showing 27 changed files with 452 additions and 443 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
language: node_js
node_js:
- "4"
- "5"
- '5'
- '6'
script:
- npm test
env:
global:
- secure: GQmuKiWbVHnPCR7WAy3NCv652dHmnmK/1LOfQlbmhan6+cSMJ5Y1aFHBSmdQ5TzNu0lvZPeTlkQrTsae7sS4gKhyXlOdDp0ILOkfdKf9T6oNwGQjzm5x0v/WFAMQzC1Mr6FLxpW/FwKhVa3Czkrx6Gv6+gkBXgbsHY1LOErisxY=
- secure: Qkknepl5raIf/A8s7tJkN1NRQPGymNomANim6VY4oMycuMwUG87uWi4yLiaTmyKQPkQb1lW+SdusYZ5Ud0cIwKI+xk0b1RxsTQkc1g18QlfNcu9BBdT2rXef729KXQJhJcYyEbM8cR+qrKuzueOz/ysU/pogDXb4Hatc6ePYGOg=
- secure: Y/lZBh0+l3206I2ytelgXnXwtHZUS0ff7kcRSOjI8P3vRqOs7UdeqlZDRQfrpW7TZ2EI4G6mR0giZGOIITC7CNWv+QYgDT/nrnih8t+Su2TGsZARR5cOUYDYxaaLMRxdiMpZ5V/veuHhJDL0C4MOd8xR56y7493cbznPvQu0jdo=
- secure: "BZ2tPb/zQoqTKsBAcIdn/YPLJAmmJLih0NtdmOZl0H2c+nl57EC2rVIdm8e0V8G2B2Ho3L5KoLiiK0LafulCRWZ/sL/vR09kGMAccGR/qITkQ4FFWm1dbdoD00G9GHz2/7igyFhgmJ7zpNTkd8ND4k++mDHmLgh40Tg0TU/Ej8Q="
- secure: "Qg60PWwbOpVTjaRHA5D2lUBAIFwFJ5iLMjlMIyKpzlXIUSxBYg7xpZSfM+sA7vDHejlIsCCgMakyexWNbBj8po3DeRv9kZKfp44/SYoGhqFGEYzifmbXWbeJfBpouIJ1t/1YBUoBjHP190+3QnzDsyvrzJtmROPkRkW752SYco0="
- secure: "Tc2RSamcEEHUqPek2t1jQWCc/ZImEgB5wF3TsWPvJ9Wx/NbMLI50yZygWR+yB9D0i6bpn/rcCbGMXVkX0qpVE0/df3KIieR23ftWbaIH1HtJcpCWY2qXdzyUAMncVrnVi3WxJsREV9on8IAjINbhalwVK4Ygoy3E3XD6iV2ibeE="
86 changes: 66 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@

Call Google Play APIs from Node. You might want to check out the [CLI](https://github.com/dweinstein/node-google-play-cli) package as well.

By default behaves like a Nexus 5X device with SDK 23 for app downloads.

# USAGE

```javascript
// Create the API object:
var api = require('gpapi').GooglePlayAPI(user, pass, android_id);

// OR (using object as first argument):
var api = require('gpapi').GooglePlayAPI({
username: user,
password: pass,
androidId: android_id
});

// usage via Promise
api.details("com.viber.voip").then(console.log);

// usage via node callback convention
api.details("com.viber.voip", function (err, res) {
console.log(err ? err : res);
}
// assumes android id of a Nexus 5X device checked in w/ Play Store 6.8.44.F
var api = require('gpapi').GooglePlayAPI({
username: user,
password: pass,
androidId: android_id
// apiUserAgent: optional API agent override (see below)
// downloadUserAgent: optional download agent override (see below)
});

// usage via Promise
api.details("com.viber.voip").then(console.log);

// usage via node callback convention
api.details("com.viber.voip", function (err, res) {
console.log(err ? err : res);
}
```
# Options
Expand All @@ -40,12 +41,57 @@ The options accepted:
androidId: androidId,
countryCode: 'us',
language: 'en_US',
requestsDefaultParams: requestsDefaultParams
requestsDefaultParams: requestsDefaultParams,
apiUserAgent: USER_AGENT,
downloadUserAgent: DOWNLOAD_MANAGER_USER_AGENT
}
```
## Defaults
The default `apiUserAgent` and `downloadUserAgent` is from Nexus 5X device, w/
Play Store version 6.8.44:
```
const USER_AGENT = (
'Android-Finsky/6.8.44.F-all%20%5B0%5D%203087104 ' +
'(api=3,versionCode=80684400,sdk=23,device=bullhead,'+
'hardware=bullhead,product=bullhead,platformVersionRelease=6.0.1,'+
'model=Nexus%205X,buildId=MHC19Q,isWideScreen=0)'
);

const DOWNLOAD_MANAGER_USER_AGENT = (
'AndroidDownloadManager/6.0.1 (Linux; U; Android 6.0.1; Nexus 5X Build/MHC19Q)'
);
```
Therefore you will have best luck getting an `ANDROID_ID` from a Nexus 5X or
override the value via the options object for your particular device.
## ID and User-Agent
Note that you'll need to grab the device-id (`ANDROID_ID`) and associated
user-agents for best performance of the library.
One way is to setup an HTTP proxy and install a CA to the device to see the
network traffic. Here is an example from a
[mitmproxy](https://github.com/mitmproxy/mitmproxy) session:
![Device ID and API User-Agent](./docs/devid-ua-1.png?raw=true "Device ID and API UA")
![Download User-Agent](./docs/download-ua.png?raw=true "Download User Agent")
These values can then be passed to the API so that apps can be downloaded with
the restrictions of the particular device.
## requests defaults
Note that this library uses the [`requests` module](https://github.com/request/request), therefore you can [control proxy behavior](https://github.com/request/request#controlling-proxy-behaviour-using-environment-variables) or override defaults via the `requestDefaultsParams` option.
## Debugging
Use env variable `DEBUG` i.e., `DEBUG=gp:api` to enable debug output. This is done via [request-debug](https://github.com/request/request-debug).
# EXAMPLES
**Assumes you have set the following environment variables: `GOOGLE_LOGIN`, `GOOGLE_PASSWORD`, `ANDROID_ID`**
Expand Down Expand Up @@ -136,9 +182,9 @@ Note that this library uses the [`requests` module](https://github.com/request/r
```javascript
± % node examples/completeDownloadInfo.js | jq '.'
{ url: 'https://android.clients.google.com/market/download/Download?packageName=com.viber.voip&versionCode=37&ssl=1&token=xxxxxxxxx&downloadId=-xxxxxxxxxxx',
jar:
jar:
RequestJar {
_jar:
_jar:
CookieJar {
enableLooseMode: true,
store: { idx: { 'android.clients.google.com': { '/market/download': { MarketDA: Cookie="MarketDA=xxxxxxxx; Path=/market/download; hostOnly=true; aAge=29ms; cAge=29ms" } } } } } },
Expand Down
Binary file added docs/devid-ua-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/download-ua.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 6 additions & 17 deletions examples/bulkDetails.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
var GooglePlayAPI = require('../lib/api').GooglePlayAPI;

var use_cache = false;
var debug = false;

function getBulkDetails(pkgs) {
var api = GooglePlayAPI(
process.env.GOOGLE_LOGIN, process.env.GOOGLE_PASSWORD,
process.env.ANDROID_ID,
use_cache,
debug
);
var api = require('./common-api-init');

function getBulkDetails (pkgs) {
return api.login()
.then(function() {
api.bulkDetails(pkgs).then(function (res) {
console.log('%j', res);
.then(function () {
api.bulkDetails(pkgs).then(function (res) {
console.log('%j', res);
});
});
});
}

var argv = require('minimist')(process.argv.slice(2));
getBulkDetails(argv._ || ['com.viber.voip', 'air.WatchESPN']);

9 changes: 9 additions & 0 deletions examples/common-api-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var GooglePlayAPI = require('../lib/api').GooglePlayAPI;

module.exports = GooglePlayAPI({
username: process.env.GOOGLE_LOGIN,
password: process.env.GOOGLE_PASSWORD,
androidId: process.env.ANDROID_ID,
useCache: false,
debug: false
});
48 changes: 13 additions & 35 deletions examples/delivery.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
var GooglePlayAPI = require('../lib/api').GooglePlayAPI;
var api = require('./common-api-init');

var use_cache = false;
var debug = false;

var api = GooglePlayAPI(
process.env.GOOGLE_LOGIN, process.env.GOOGLE_PASSWORD,
process.env.ANDROID_ID,
use_cache,
debug
);

function getDeliveryData(pkg) {
function getDeliveryData (pkg) {
return api.login()
.then(function() {
api.details(pkg).then(function (res) {
return res.details.appDetails.versionCode;
})
.then(function (versionCode) {
return api.deliveryData(pkg, versionCode);
})
.then(function (info) {
console.log('%j', info);
.then(function () {
api.details(pkg).then(function (res) {
return res.details.appDetails.versionCode;
})
.then(function (versionCode) {
return api.deliveryData(pkg, versionCode);
})
.then(function (info) {
console.log('%j', info);
});
});
});
}

function getDeliveryDataVc(pkg, vc) {
return api.login()
.then(function() {
return api.deliveryData(pkg, vc);
})
.then(function (info) {
console.log('%j', info);
});
}


var argv = require('minimist')(process.argv.slice(2));
var pkg = argv._[0] || argv.p || "com.viber.voip";
var pkg = argv._[0] || argv.p || 'com.viber.voip';
getDeliveryData(pkg);

17 changes: 3 additions & 14 deletions examples/details.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
var GooglePlayAPI = require('../lib/api').GooglePlayAPI;

var use_cache = false;
var debug = false;

function getAppDetails(pkg) {
var api = GooglePlayAPI(
process.env.GOOGLE_LOGIN, process.env.GOOGLE_PASSWORD,
process.env.ANDROID_ID,
use_cache,
debug
);
var api = require('./common-api-init');

function getAppDetails (pkg) {
return api.details(pkg).then(function (res) {
console.log('%j', res);
});
}

var argv = require('minimist')(process.argv.slice(2));
var pkg = argv._[0] || argv.p || "com.viber.voip";
var pkg = argv._[0] || argv.p || 'com.viber.voip';
getAppDetails(pkg);

30 changes: 8 additions & 22 deletions examples/download.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
var GooglePlayAPI = require('../lib/api').GooglePlayAPI;

var use_cache = false;
var debug = false;

var api = require('./common-api-init');
var fs = require('fs');

function downloadToFile(pkg, vc) {

var api = GooglePlayAPI(
process.env.GOOGLE_LOGIN, process.env.GOOGLE_PASSWORD,
process.env.ANDROID_ID,
use_cache,
debug
);

function downloadToFile (pkg, vc) {
return api.details(pkg).then(function (res) {
return vc || res.details.appDetails.versionCode;
})
.then(function (versionCode) {
var fStream = fs.createWriteStream(pkg+'.apk');
return api.download(pkg, versionCode).then(function (res) {
res.pipe(fStream);
.then(function (versionCode) {
var fStream = fs.createWriteStream(pkg + '.apk');
return api.download(pkg, versionCode).then(function (res) {
res.pipe(fStream);
});
});
});
}


var argv = require('minimist')(process.argv.slice(2));
var pkg = argv._[0] || argv.p || "com.MediaConverter";
var pkg = argv._[0] || argv.p || 'com.MediaConverter';
var vc = argv._[1] || argv.v;
downloadToFile(pkg, vc);

39 changes: 13 additions & 26 deletions examples/downloadInfo.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
var GooglePlayAPI = require('../lib/api').GooglePlayAPI;

var use_cache = false;
var debug = false;

function getDownloadInfo(pkg) {

var api = GooglePlayAPI(
process.env.GOOGLE_LOGIN, process.env.GOOGLE_PASSWORD,
process.env.ANDROID_ID,
use_cache,
debug
);
var api = require('./common-api-init');

function getDownloadInfo (pkg) {
return api.login()
.then(function() {
api.details(pkg).then(function (res) {
return res.details.appDetails.versionCode;
})
.then(function (versionCode) {
return api.downloadInfo(pkg, versionCode);
})
.then(function (info) {
console.log('%j', info);
.then(function () {
api.details(pkg).then(function (res) {
return res.details.appDetails.versionCode;
})
.then(function (versionCode) {
return api.downloadInfo(pkg, versionCode);
})
.then(function (info) {
console.log('%j', info);
});
});
});
}


getDownloadInfo("air.WatchESPN");

getDownloadInfo('air.WatchESPN');
Loading

0 comments on commit 82c0550

Please sign in to comment.