Jak wykonać wywołanie API za pomocą meteor

Ok tutaj jest twitter API,

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

Czy ktos moze mi podpowiedziec jak zrobic to API lub link za pomoca Meteor

Aktualizacja::

Oto kod, który próbowałem, ale nie pokazuje żadnej odpowiedzi

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

Definiujesz swój checkTwitter Meteor.metoda wewnątrz bloku o zasięgu klienta. Ponieważ nie możesz wywołać cross domain od Klienta (chyba że używasz jsonp), musisz umieścić ten blok w Meteor.isServer bloku.

Na marginesie, zgodnie z dokumentacją , strona klienta Meteor.method twojej funkcji checkTwitter jest jedynie stub metody po stronie serwera. Zapoznaj się z dokumentami, aby dowiedzieć się, jak działają serwery i klienty Meteor.methods razem.

Oto działający przykład wywołania 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/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-15 15:22:47

Może to wydawać się prymitywne - ale pakiet HTTP nie jest domyślnie dostępny w Twoim projekcie Meteor i wymaga zainstalowania go a la carte.

W wierszu poleceń:

  1. Tylko Meteor:
    meteor dodaj http

  2. Meteoryt:
    mrt dodaj 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/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-20 12:45:01

Meteor.http.get on the client jest asynchroniczny, więc musisz podać funkcję callback:

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/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-14 16:17:43

Użyj Meteor.http.get. Na docs :

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

Dokumenty rzeczywiście zawierają kilka przykładów korzystania z Twittera, więc powinieneś być w stanie zacząć z nimi.

 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/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-14 15:02:35

Po stronie serwera, jeśli dostarczysz połączenie z powrotem do http.get it will be asynch call so my solutions to that undefined return on client was

Var result = HTTP.get (iurl); return result.data.odpowiedź;

Ponieważ nie przekazałem połączenia do HTTP.get so it waited until I got response. hope it helps

 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/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-28 21:21:23