Как получить JSON с сетевым модулем SparkAR - PullRequest
1 голос
/ 09 июля 2019

Я хочу извлечь данные из URL-адреса с помощью сетевого модуля SparkAR и отобразить его.

Я попробовал пример, найденный в документации Spark AR, но он мало что делает: https://developers.facebook.com/docs/ar-studio/reference/classes/networkingmodule/

Не забудьте сначала добавить "jsonplaceholder.typicode.com" в белые списки Spark AR.:)

// Load in the required modules
const Diagnostics = require('Diagnostics');
const Networking = require('Networking');

//==============================================================================
// Create the request
//==============================================================================

// Store the URL we're sending the request to
const url = 'https://jsonplaceholder.typicode.com/posts';

// Create a request object
const request = {

  // The HTTP Method of the request
  // (https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)
  method: 'POST',

  // The HTTP Headers of the request
  // (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers)
  headers: {'Content-type': 'application/json; charset=UTF-8'},

  // The data to send, in string format
  body: JSON.stringify({title: 'Networking Module'})

};

//==============================================================================
// Send the request and log the results
//==============================================================================

// Send the request to the url
Networking.fetch(url, request).then(function(result) {

  // Check the status of the result
  // (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
  if ((result.status >= 200) && (result.status < 300)) {

    // If the request was successful, chain the JSON forward
    return result.json();

  }

  // If the request was not successful, throw an error
  throw new Error('HTTP status code - ' + result.status);

}).then(function(json) {

  // Log the JSON obtained by the successful request
  Diagnostics.log('Successfully sent - ' + json.title);

}).catch(function(error) {

  // Log any errors that may have happened with the request
  Diagnostics.log('Error - ' + error.message);

});

Все, что я получаю, это: ">> Успешно отправлено - Сетевой модуль"

Кто-нибудь знает, как я могу отобразить содержимое json в консоли, которую я хочусохраните его и потом используйте в текстовом объекте.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...