How to make an API call using a meteorite

Ok, here is the twitter API

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

Can someone give me a hint on how to access this API or link using Meteor

Update ::

Here is the code I tried but not showing any answer

 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 () { }); } 
+43
json javascript api meteor twitter
Jan 14 '13 at 14:45
source share
5 answers

You define your checkTwitter Meteor.method inside a block with a client scope. Since you cannot call the cross-domain from the client (if you are not using jsonp), you must put this block in the Meteor.isServer block.

Aside from the documentation, the client side of Meteor.method your Meteor.method function is just a server stub - a side method. You will want to check the documents for a full explanation of how the server and client sides of Meteor.methods work together.

Here is a working example of an http call:

 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 }); } 
+56
Jan 14 '13 at 17:39
source share

This may seem rudimentary - but the HTTP package is not used by default in your Meteor project and requires that you install it on a la-map.

At the command line:

  • Just a Meteor:
    Meteor add http

  • Meteorite:
    mrt add http

Meteor HTTP Protocols

+29
Sep 20 '13 at 12:45
source share

Meteor.http.get on the client is asynchronous, so you need to provide a callback function:

 Meteor.http.call("GET",url,function(error,result){ console.log(result.statusCode); }); 
+6
Jan 14 '13 at 16:17
source share

Use Meteor.http.get . On docs :

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

There are some examples of using Twitter in the docs, so you can start with them.

+4
Jan 14 '13 at 15:02
source share

on the server side, if you send the request to http.get, it will be an asynchronous call, so my solutions for returning undefined on the client were

var result = HTTP.get (iurl); return result.data.response;

since I didn’t pass the HTTP.get callback, so it was waiting until I received the response. hope this helps

0
Jan 28 '16 at 21:21
source share



All Articles