2020. 2. 17. 04:41ㆍ안드로이드 개발
Print apks list of specific packageName using googleapi, androidpublisher and service account authentication (v3).
const {google} = require('googleapis');
const key = require('./privateKey.json')
const packageName = "com.company.example"
let client = new google.auth.JWT(
key.client_email,
undefined,
key.private_key,
['https://www.googleapis.com/auth/androidpublisher']
)
const androidApi = google.androidpublisher({
version: 'v3',
auth: client
})
async function getApksList() {
let authorize = await client.authorize();
//insert edit
console.log('authorize :', authorize);
let res = await androidApi.edits.insert({
packageName: packageName
})
//get edit id
let editId = res.data.id
const res = await androidApi.edits.apks.list({
editId: editId,
packageName: packageName
});
console.log(`Result ${(JSON.stringify(res))}`);
}
getApksList().catch(console.error);
Google Developer Console
-
"Google Developer Console" > "APIs & Auth" subcategory "APIs" > (api list) "Google Play Android Developer API". Set "STATUS" to "ON".
-
"APIs & auth" subcategory "Credentials" > "Create new Client ID". Choose "Service account" and create the id.
-
You should get a P12 key from the browser.
Google Play Developer Console
-
"Google Play Developer Console" > "Settings" > subcategory "API access".
-
Make a link to your "Linked Project".
-
"Service Account" place may be already showing your "Service account" CLIENT ID which made "google developer console".
By default this account is gray indicating that it is not active. So you must activate it and set authority manually.
You should now get a correct response from the API.