Created
March 27, 2018 15:53
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { google } = require("googleapis"); | |
const publisher = google.androidpublisher("v2"); | |
const OAuth2 = google.auth.OAuth2(); | |
const SERVICE_ACCOUNT_EMAIL = "[email protected]"; | |
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