Write json file to Firebase with Node.js?

I have a third party API that I need to call every 5 seconds. I get JSON as response, and I’d like to write the JSON content to a Firebase node using Node.js. Based on Firebase examples I could import data with this code:

var usersRef = ref.child("users");
usersRef.set({
  alanisawesome: {
    date_of_birth: "June 23, 1912",
    full_name: "Alan Turing"
  },
  gracehop: {
    date_of_birth: "December 9, 1906",
    full_name: "Grace Hopper"
  }
});

Curl examples worked too. But what I really wanted to do is to import a third party API response directly to my Firebase database using the API endpoint. How can i do it with Node.js?


Source: stackoverflow-javascript

How to convert Array to JSON

need your help about this one…
how can i convert this arrays to json code…

here’s my code:

$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

// Will dump a beauty json :3
var_dump(json_decode($result, true));

$result = file_get_contents($url);
// Will dump a beauty json :3
var_dump(json_decode($result, true));

enter image description here


Source: stackoverflow-php

Logical display of dynamic data in 3d HTMl5

I cant reveal my project details here. So I am taking an example of Electrical circuit.

Suppose we have 10 lights at home and there is a centrepoint from where the electricity flows to the lights when switched on. I want to draw a logical view that at a given time, from the centrepoint, to what lights the electricity is flowing.

This representation should be in 3d View. Imagine, I have been provided with a unique symbol for centrepoint and switch.

My thought process towards this is generate a json data from my application and feed this data to HTML5 which can render the json data into 3D representation.

But my query is, the data I have is quiet complex. Say, centrepoint is connected to many subnets and set of lights are connected to each of the subnet and at a given point, what subnet is connected to centrepoint and what lights are getting electricity is connect to the particular subnet. I should show neither the subnet nor the lights which is not getting the electricity (assuming, electricity will flow to subnet when atleast one light is glowing from that subnet)

How can I render this dynamic data in HTML5 in 3d?

Kindly please point me to the example projects in github.com or direct me right tutorial.

If HTML5 is not the right choice, Kindly please direct me to the right technology that I can use to do this?


Source: stackoverflow-javascript

Convert Json parsed date to fit html5 input date

I am using Knockout to make a nice looking Gui like so

Javascript:

   viewModel = {
        lookupCollection: ko.observableArray()
    };

    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url:  "@Url.Action("GetView", "FakturaOmfangs", new {area = "" , id = ViewBag.id})",
        }).done(function (data) {
            $(data).each(function (index, element) {
                var mappedItem =
                    {
                        FakturaId: ko.observable(element.FakturaId),
                        FakturaProdukterId: ko.observable(element.FakturaProdukterId),
                        Beskrivelse: ko.observable(element.Beskrivelse),
                        Periode: ko.observable(element.Periode),
                        EndDate: ko.observable(element.EndDate),
                        procent: ko.observable(element.procent),
                        Rabat: ko.observable(element.Rabat),
                        Pris: ko.observable(element.Pris),
                        Ialt: ko.observable(element.Ialt),
                        Value: ko.observable(element.Value),
                        Mode: ko.observable("display")
                    };
                console.log(mappedItem);
                viewModel.lookupCollection.push(mappedItem);
            });
            ko.applyBindings(viewModel);
        });
    });

the EndDate is a Datetime? parsed from controller like this

  return Json(list, JsonRequestBehavior.AllowGet);

This is my input where i would like to put the Date into, so i can edit it.

<td><input class="form-control" type="date" data-bind="value: EndDate" /></td>

How do i format the date to the correct format? so that i can use it in input type=Date ?

Thanks.
Benny.


Source: stackoverflow-javascript

How to parse JSON object at jsp

I wauld parse JSON object(List) which the i pass from controller. I want to convert my JSON object in html, but I want to extract each parameter separately.

@JsonView(View.Public.class)
@RequestMapping(value = "/updatecomments", method = RequestMethod.GET)
@ResponseBody
public List<Commentary> updateCommentary(@RequestParam int idEvent) {
    System.out.println("updatecomm: " + idEvent);
    Event event = eventService.findById(idEvent);
    List<Commentary> comments = event.getComments();
    return comments;
}

when i parse with this function it’s work:


    function updateComments() {
        $.ajax({
            url : "/updatecomments",
            method : 'GET',
            data : {
                idEvent: ${event.getId()},
            },
            dataType : 'json',
            success : function(results){
                alert("succes");
                var json = "

Ajax Response

"
                    + JSON.stringify(results, null, 4) + "

";
$('#feedback').html(json);
}
});
};

but when i would parse with this code, it isn’t work:


    function updateComments() {
        $.ajax({
            url : "/updatecomments",
            method : 'GET',
            data : {
                idEvent: ${event.getId()},
            },
            dataType : 'json',
            success : function(results){
                alert("succes");

                
                    alert(${comment.description});
                    alert(1);
                
            }
        });
    };

This function also does not work

var comments = $.parseJSON(results);

What is my mistake?


Source: stackoverflow-javascript

jQuery-Trying to emulate a simple Facebook info and feed page through Facebook Graph API

Im trying to emulate a simple page which includes facebook info like username, email etc. I’m not able to obtain the user’s posts from the json received. Tried various methods like making the feed a different function but all failed. Please help.

$(document).ready(function() {
  var fbtoken = 'your token here';

  function getInfo() {

    $.ajax('https://graph.facebook.com/me?access_token=' + fbtoken, {

        success: function(response) {
          console.log(response);
          console.log(typeof(response));
          $("#Id").html('<a target="blank" href="https://facebook.com/' + response.id + '">https://facebook.com/' + response.id + '</a>');
          $('#name').text(response.name);
          $('#about').text(response.about);
          $('#birthday').text(response.birthday);
          $("#email").text(response.email);
          $("#feed").text(response.posts.data);



        }

      }

    );
  }

  $("#load").on('click', getInfo)
});
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  https://code.jquery.com/jquery-3.2.1.min.js
  http://FacebookPro.js
  <title>Facebook Mockup</title>
</head>

<body>
  

My Facebook Mockup

Run

Id

Name

About

Birthday

Email

</div> <h2 align="center">Feed</h2>

FB Feed=

</div> </div> </body> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> </html>

You can insert your token in the fbToken variable using Graph API Explorer in Tools And Support. I think i'm making a mistake in retrieving the data part as it is an object-of-array but i'm having a hard time figuring out how to do it right.

Source: stackoverflow-javascript

How to loop on json object array jquery?

i want to loop on output of json array object how to do that ?
thats the output of json array object after performing query on it

Object {0: Object, 1: Object, 3: Object, 5: Object}
0:Object
certificate:""
country:"Egypt"
created_at:"2017-04-26 20:39:22"
description:"  "
end_date:"2017-04-22"
event_id:1
id:1
name:"Project Management"
pic:"4537c00b63a920f5d1a49bd37b01e789.jpg"
1:Object
3:Object
5:Object

i tried to write such code but it didnt worked i just accessed first and second elements only . it seems that i didnt write right loop .

 var arr=JSON.parse(this.responseText);

                
                   console.log(arr);                  
                
                 var count= Object.keys(arr).length;
                  console.log(Object.keys(arr).length);
                  if(count!=0)
                  {
                    for(var i=0;i<count;i++)
                    { if(arr[i].type=="img")
                    }


Source: stackoverflow-php

Return blank page when using gravity form api?

Following is my code:

$api_key = 'XXXXXX';
$private_key = 'XXXXXXXXXXXXXXXXXX';
$expires = strtotime( '+60 mins' );

// Insert data for Property Upload Form.
$route_1 = 'forms/8/results';
$string_to_sign_1 = sprintf( '%s:%s:%s:%s', $api_key, 'GET', $route_1, $expires );
$hash_1 = hash_hmac("sha1", $string_to_sign_1, $private_key, true);
$sig_1 = rawurlencode(base64_encode($hash_1));
$url_1 = 'https://www.abc.com.au/gravityformsapi/' . $route_1 . '?paging[page_size]=1000&api_key=' . $api_key .'&signature=' . $sig_1 . '&expires=' . $expires;
echo $url_1;

$response_1 = file_get_contents($url_1,false,NULL);

$test_1 = json_decode($response_1);
print_r($test_1);exit;

it returns a blank page, when i hit on my $url_1, it’s just redierect on some other page.
if i click on ‘https://www.abc.com.au/gravityformsapi/forms/‘, it still shows blank data.


Source: stackoverflow-php

Why is node giving me this error?

i’ve been trying to make my first twitter bot, but when I run npm run dev I get this error:

> Tweeter@1.0.0 dev /mnt/c/Users/rfasc/Dropbox/Hackathon/HackCuTwitter
> node app.js

npm ERR! weird error 1
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! not ok code 0 

am somewhat new to using nodejs and the npm commmands to connect my code. Here is my package.json and my app.js file:

package.json:

{
  "name": "Tweeter",
  "version": "1.0.0",
  "description": "package.json tester",
  "main": "app.js",
  "dependencies": {
    "twitter": "^1.7.0",
    "twitter-stream-api": "^0.5.1"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1",
    "dev": "node app.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/kennychiwa/HackCuTwitter.git"
  },
  "author": "",
  "license": "BSD-2-Clause",
  "bugs": {
     "url": "https://github.com/kennychiwa/HackCuTwitter/issues"
  },
  "homepage": "https://github.com/kennychiwa/HackCuTwitter#readme"
}

and app.js:

var twitterpack = require('twitter');

var tokens {
  consumer_key: '-------9WJSaaqAe9yVvr30CF',
  consumer_secret: '-------------------fj3zoiZ2nUOTBWUjP4DqtGXIlzzbxbOY',
  token_key: '  ----------zNHmdL43N6RZJeOtJeH8ZhrursJUQlAqCycHqxbl',
  tokenk_secre: '----EcxAjUq1hLka2QYwSSZStETF7Mr2mBikHYCTTqodV'
}
var twitter = new twitterpack(tokens);

Twitter.stream('statuses/filter', {track: 'hey'}, function(stream) {

  stream.on('data', function(stream){

    console.log(tweet.text);
    var meanReply = {status: "hey @" + tweet.user.screen_name}
    Twitter.post('statuses/update', meanReply, function(error, tweetReply, 
response){
      if(error) {console.log(error) /*&&db.collection('errors', 
error.text)*/};
      console.log(tweetReply.text)}
     );


  });
   stream.on('error', function(error) {
   console.log(error);
  });
});

please help, thanks.


Source: stackoverflow-javascript