I am using Spark AR to create a simple effect that grabs text from an api and displays it.
Here is my code
const Scene = require('Scene');
const Diagnostics = require('Diagnostics');
const Patches = require('Patches');
const Textures = require('Textures');
const Materials = require('Materials');
const Networking = require('Networking');
const URL = 'https://gabby-airbus.glitch.me/random';
Networking.fetch(URL).then(function(result){
if( (result.status >=200) && (result.status < 300)){ return result.json(); }
else { throw new Error('HTTP Status Code: ' + result.status); }
}).then(function(json){
// show json data in console
Diagnostics.log(json.item);
// Asign json data to text object
itemText.text = json.item;
}).catch(function(error){
itemText = 'Failed to start';
Diagnostics.log(result.status + error);
});
I get the following error
Error:Cannot read property 'fetch' of undefined
{
"line": 12,
"column": 17,
"sourceURL": "script.js"
}
I am not sure why i am getting undefined when https://gabby-airbus.glitch.me/random is clearly not undefined. it has a random json object.
I am following the solution suggested in this SO post