I'm using a Javascript file to try and get a token from ArcGIS Online. However, whenever I try it, it comes back with
init.js:11 Uncaught Error: undefinedModule
The file (GetAToken.js) is below:
dojo.ready(init);
var request = dojo.require('request'); // npm install request
// generate a token with your client id and client secret
function getToken(callback) {
request.post({
url: 'https://www.arcgis.com/sharing/rest/oauth2/token/',
json: true,
form: {
'f': 'json',
'client_id': '<<MY_CLIENT_ID>>',
'client_secret': '<<MY_CLIENT_SECRET>>',
'grant_type': 'client_credentials',
'expiration': '1440'
}
}, function (error, response, body) {
console.log(body.access_token);
callback(body.access_token);
});
}
And the bit which calls it (in a HTML file) is:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://esri.github.io/calcite-bootstrap/assets/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://js.arcgis.com/4.0/esri/css/main.css">
<script src="https://js.arcgis.com/4.0/"></script>
<script src="GetAToken.js">
var MyToken = callback(getToken);
alert(MyToken);
</script>