Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmosier/8a0d3aa31129f00f92963180376b979f to your computer and use it in GitHub Desktop.
Save jamesmosier/8a0d3aa31129f00f92963180376b979f to your computer and use it in GitHub Desktop.
Example, using Node, on how to get user subscriptions using the Google Play Developer API (with androidpublisher role)
const { google } = require("googleapis");
const publisher = google.androidpublisher("v2");
const OAuth2 = google.auth.OAuth2();
const SERVICE_ACCOUNT_EMAIL = "some_google_acccount@gmail.com";
const SERVICE_ACCOUNT_KEY_FILE = require("./path/to/credentials.json");
const jwtClient = new google.auth.JWT(
SERVICE_ACCOUNT_KEY_FILE.client_email,
null,
SERVICE_ACCOUNT_KEY_FILE.private_key,
["https://www.googleapis.com/auth/androidpublisher"],
null
);
jwtClient.authorize(function(err, tokens) {
if (err) {
console.log("There was an error :(", err);
return;
}
publisher.purchases.subscriptions.get(
{
auth: jwtClient,
packageName: "com.your.android.package",
subscriptionId: "The purchased subscription ID (for example: monthly001)",
token:
"The token provided to the users device when the subscription was purchased"
},
function(error, response) {
if (error) {
throw error;
}
console.log("Hey, we got a response!");
console.log(response.data);
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment