【问题标题】:Upload APK and set track for publishing上传 APK 并设置发布轨道
【发布时间】:2018-12-11 11:31:54
【问题描述】:

我正在尝试设置新轨道并上传 APK 以使用 nodejs 发布...但是没有上传 APK 也没有轨道集。

但是验证和所有其他步骤的结果完全符合我的预期(根据API)。脚本成功了,但开发人员控制台中没有任何变化......那么有没有一位魔法大师可以看到我的问题?

注意 1:我确实手动发布了我的应用程序,因为 android-publisher 仅用于更新之前已发布的应用程序

注意 2:这之前(很久以前)有效,并且已经停止工作了一段时间,我终于有时间更新所有内容

我的代码:

var google = require('googleapis').google;
var Promise = require('bluebird');
var _ = require('lodash');
var settings = require('./config/settings.json');

// Enable API access into the Developer Console: https://play.google.com/apps/publish/?account=7639196906174529268#ApiAccessPlace
// Create a service account
// Download the JSON and save it here
// Make sure the email of the JSON is added to the apps for release manager role:
// https://play.google.com/apps/publish/?account=7639196906174529268#AdminPlace
var key = require('./config/google-play-user.json');

// editing "scope" allowed for OAuth2
var scopes = [
    'https://www.googleapis.com/auth/androidpublisher'
];

var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2();
var jwtClient = new google.auth.JWT(key.client_email, null, key.private_key, scopes, null);
var play = google.androidpublisher({
    version: 'v3',
    auth: oauth2Client,
    params: {
        // default options
        // this is the package name for your initial app you've already set up on the Play Store
        packageName: settings.app.id
    }
});

google.options({auth: oauth2Client});

// Start with a new edit.
startEdit().then(function(data) {
    // Load our APK(in this case a Cordova APK).
    var standardAPK = require('fs').readFileSync('./platforms/android/build/outputs/apk/android-release.apk');

    // Stage the upload (doesn't actually upload anything).
    return upload({
        edit: data.edit,
        apk: standardAPK,
        key: 'standardApk'
    });

}).then(function(data) {
    // Set our track.
    return setTrack(data);
}).then(function(data) {
    // Validate our changes.
    return validateToPlayStore(data);
}).then(function(data) {
    console.log('Successful uploaded APK files:', data);
}).catch(function(err) {
    console.log(err);
    process.exit(1);
});

/**
 *  Sets our authorization token and begins an edit transaction.
 */
function startEdit() {
    return new Promise(function(resolve, reject) {
        jwtClient.authorize(function(err, tokens) {
            if (err) {
                console.log(err);
                process.exit(1);
                return;
            }

            // Set the credentials before we doing anything.
            oauth2Client.setCredentials(tokens);

            play.edits.insert({
                packageName: settings.app.id
            }, function(err, edit) {
                if (err || !edit) { reject(err); }

                resolve({
                    edit: edit.data
                });
            });
        });
    });
}

/**
 *  Stages an upload of the APK (but doesn't actually upload anything)
 */
function upload(data) {
    var edit = data.edit;
    var apk = data.apk;
    var key = data.key;

    return new Promise(function(resolve, reject) {
        play.edits.apks.upload({
            editId: edit.id,
            packageName: settings.app.id,
            media: {
                mimeType: 'application/vnd.android.package-archive',
                body: apk
            }
        }, function(err, res) {
            if (err || !res) { reject(err); }

            // Pass any data we care about to the next function call.
            var obj = {};
            obj[key] = res.data;
            resolve(_.omit(_.extend(data, obj), 'apk'));
        });
    });
}

/**
 *  Sets our track (beta, production, etc.)
 */
function setTrack(data) {
    var edit = data.edit;
    var track = 'production';

    return new Promise(function(resolve, reject) {
        play.edits.tracks.update({
            editId: edit.id,
            track: track,
            packageName: settings.app.id
        }, function(err, res) {
            if (err || !res) { reject(err); }

            resolve(_.extend(data, {setTrackResults: res.data}));
        });
    });

}

/**
 *  Validates our edit transaction and makes our changes live.
 */
function validateToPlayStore(data) {
    return new Promise(function(resolve, reject) {
        // play.edits.commit({ // Commit will set the change LIVE
        play.edits.validate({ // Validate will only validate it, not set it LIVE.
            editId: data.edit.id,
            packageName: settings.app.id
        }, function(err, res) {
            if (err || !res) { reject(err); }

            resolve(_.extend(data, {validateToPlayStoreResults: res.data}));
        });
    });
}

最初来自http://frontendcollisionblog.com/javascript/2015/12/26/using-nodejs-to-upload-app-to-google-play.html,当时它仍然有效

【问题讨论】:

  • 当您尝试在控制台中更新您的应用时,您需要向我们展示发生了什么。

标签: android node.js google-api-nodejs-client


【解决方案1】:

您可以使用apkup 将 APK 上传到 Google Play。 apkup 基本上是 googleapis 包的友好包装器/CLI。

CLI 示例:

npx apkup \
  --key ./config/google-play-user.json \
  --release-notes "en-US=lorem ipsum dolor" \
  --apk ./platforms/android/build/outputs/apk/android-release.apk

Node.js 示例:

const { Apkup } = require('apkup')
const key = require('./config/google-play-user.json')

const apkup = new Apkup(key)

apkup
  .upload('./platforms/android/build/outputs/apk/android-release.apk', {
    releaseNotes: [
      {
        language: 'en-US',
        text: 'Minor bug fixes...'
      }
    ]
  })
  .then(data => {
    console.log(` > ${data.packageName} version ${data.versionCode} is up!`)
  })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-15
    相关资源
    最近更新 更多