Cómo hacer una llamada a la API usando meteor


Ok aquí está la API de twitter,

http://search.twitter.com/search.atom?q=perkytweets

¿Puede alguien darme alguna pista sobre cómo llamar a esta API o enlace usando Meteor

Actualizar::

Aquí está el código que probé pero no muestra ninguna respuesta

if (Meteor.isClient) {
    Template.hello.greeting = function () {
        return "Welcome to HelloWorld";
    };

    Template.hello.events({
        'click input' : function () {
            checkTwitter();
        }
    });

    Meteor.methods({checkTwitter: function () {
        this.unblock();
        var result = Meteor.http.call("GET", "http://search.twitter.com/search.atom?q=perkytweets");
        alert(result.statusCode);
    }});
}

if (Meteor.isServer) {
    Meteor.startup(function () {
    });
}
Author: jononomo, 2013-01-14

5 answers

Estás definiendo tu Meteoro checkTwitter .método dentro de un bloque de ámbito cliente. Debido a que no puede llamar a cross domain desde el cliente (a menos que use jsonp), debe colocar este bloque en un bloque Meteor.isServer.

Como un lado, según la documentación , el lado cliente Meteor.method de su función checkTwitter es simplemente un stub de un método del lado servidor. Querrá consultar los documentos para obtener una explicación completa de cómo funcionan el lado del servidor y el lado del cliente Meteor.methods junto.

Aquí hay un ejemplo de funcionamiento de la llamada http:

if (Meteor.isServer) {
    Meteor.methods({
        checkTwitter: function () {
            this.unblock();
            return Meteor.http.call("GET", "http://search.twitter.com/search.json?q=perkytweets");
        }
    });
}

//invoke the server method
if (Meteor.isClient) {
    Meteor.call("checkTwitter", function(error, results) {
        console.log(results.content); //results.data should be a JSON object
    });
}
 57
Author: TimDog,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-15 15:22:47

Esto puede parecer rudimentario, pero el paquete HTTP no viene por defecto en su proyecto Meteor y requiere que lo instale a la carta.

En la línea de comandos:

  1. Solo Meteor:
    meteor add http

  2. Meteorito:
    mrt add http

Meteor HTTP Docs

 29
Author: user2132316,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-20 12:45:01

Meteoro.http.get on el cliente es async, por lo que deberá proporcionar una función de devolución de llamada:

Meteor.http.call("GET",url,function(error,result){
     console.log(result.statusCode);
});
 6
Author: Lander Van Breda,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-14 16:17:43

Use Meteor.http.get. Por el docs:

Meteor.http.get(url, [options], [asyncCallback]) Anywhere
Send an HTTP GET request. Equivalent to Meteor.http.call("GET", ...).

Los documentos en realidad incluyen algunos ejemplos de uso de Twitter, por lo que debería poder comenzar con ellos.

 4
Author: Rahul,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-14 15:02:35

En el lado del servidor si devuelve la llamada a http.get it will be asynch call so my solutions to that undefined return on client was

Var result = HTTP.get (iurl); devuelve el resultado.datos.respuesta;

Como no pasé una llamada de vuelta a HTTP.así que esperó hasta que recibí respuesta. espero que ayude

 0
Author: Mr Megamind,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-28 21:21:23