答案 0 :(得分:0)
'use strict';
var soundcloudnodejs = require('soundcloudnodejs');
var fs = require('fs');
var credentials = require('credentials');
var options = {
client_id: process.env.client_id || credentials.client_id,
client_secret: process.env.client_secret || credentials.client_secret,
grant_type: process.env.grant_type || credentials.grant_type,
redirect_uri: process.env.redirect_uri || credentials.redirect_uri,
username: process.env.username || credentials.username,
password: process.env.password || credentials.password
};
soundcloudnodejs.getToken(options).then(function (token) {
if (!token || !token.access_token) {
console.log('getToken err: undefined token.access_token ');
} else {
var track = {
title: 'dog_example',
description: 'dog_example',
genre: 'dog_example',
artwork_data: __dirname + '/artist/artist.jpeg',
sharing: 'public',
oauth_token: token.access_token,
asset_data: __dirname + '/artist/artist_*.mp3'
};
soundcloudnodejs.addTrack(track, function (err, track) {
if (err) {
console.log(err)
}
console.log(track);
});
}
});