0

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

Dinero
  • 1,070
  • 2
  • 19
  • 44
  • `require('Networking')` what is this? – Vivek Doshi May 21 '20 at 01:30
  • https://sparkar.facebook.com/ar-studio/learn/documentation/reference/classes/networkingmodule/ @VivekDoshi I am using this Vivek. – Dinero May 21 '20 at 01:32
  • 1
    "We’re temporarily disabling this capability while we work to improve performance and functionality. We'll reintroduce networking in the near future." – Vivek Doshi May 21 '20 at 01:35
  • @VivekDoshi - oh crap that explains, so i guess is there any other way that i can fetch data from api? – Dinero May 21 '20 at 01:37

1 Answers1

0

Currently it is not possible, the Networking capability is disabled for security reasons. There is a plan to have it back soon though.

https://sparkar.facebook.com/ar-studio/learn/reference/classes/networkingmodule

JackKalish
  • 1,555
  • 2
  • 15
  • 24