Ok here is the twitter API,
http://search.twitter.com/search.atom?q=perkytweets
Can any one give me any hint about how to go about calling this API or link using Meteor
Update::
Here is the code that i tried but its not showing any response
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 () { }); }
Meteor. call() is typically used to call server-side methods from the client-side. However, you can also use Meteor. call() on the server-side to call another server-side function, though this is not recommended.
There are many different ways to make an API call in JavaScript ranging from using vanilla JavaScript to jQuery to using other tools that vastly simplify making API calls. We will use a vanilla JavaScript approach in this lesson. In later lessons, we will rewrite our code to make our API call in different ways.
You are defining your checkTwitter Meteor.method inside a client-scoped block. Because you cannot call cross domain from the client (unless using jsonp), you have to put this block in a Meteor.isServer
block.
As an aside, per the documentation, the client side Meteor.method
of your checkTwitter function is merely a stub of a server-side method. You'll want to check out the docs for a full explanation of how server-side and client-side Meteor.methods
work together.
Here is a working example of the 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 }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With