I am working on making an API that will give the user the number of messages they have. I have the following code:
var Scratch = require('scratch-api');
var fetch = require('node-fetch');
Scratch.UserSession.load(function(err, user) {
user.cloudSession(526698636, function(err, cloud) {
cloud.on('set', function(name, value) {
console.log(name, value);
Scratch.CloudSession.get('☁ r').onchange = function(){
var i = Scratch.CloudSession.get('☁ user').toString();
var s = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_"];
i = i.split('123456789');
var e = 0;
while(e < i.length){
e[e] == s[Number(i[e])+1];
i++;
}
i = i.toString();
fetch('https://api.scratch.mit.edu/users/' + i + '/messages/count')
.then(res => res.text())
.then(text => {
var t = text.split('{')[1].split(':')[1].split('}')[0];
Scratch.CloudSession.set('☁ cloud data', t);
Scratch.CloudSession.set('☁ r', 0);
});
}
});
})
})
However, it does not seem to work. Here is the project: API test What should I do to fix it? Where is the problem?