How to make an API call using meteor

后端 未结 5 2078
别跟我提以往
别跟我提以往 2020-12-07 10:19

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

5条回答
  •  渐次进展
    2020-12-07 11:10

    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
        });
    }
    

提交回复
热议问题