Ok here is the twitter API,

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

谁能给我一些关于如何使用Meteor调用此API或链接的提示

Update::

下面是我try 的代码,但没有显示任何响应

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

推荐答案

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

Json相关问答推荐

如何让jq输出长数据集?

时间和日期数据绘制不正确

Jolt转换,如果任何字段为空,则将对象值设置为空

JSON:将项';S键/名称移动到属性中,并使用JQ将其转换为数组

如何在VegaLite中应用Times New Roman,CaliBiri字体

Azure Data Factory JSON输出格式问题

我发现GoFr响应总是包含在数据字段中,如何返回自定义响应?

Powershell ConvertFrom-Json 意外地从包含字符串的单个项目数组生成字符串而不是对象数组

如何实现一个通用的 serde_json::from_str

使用 ConvertFrom-Json 后,Powershell 访问 JSON 中的嵌套对象

如果有 1 个元素,如何防止 ConvertFrom-Json 折叠嵌套数组

JSON 模式实际用于什么目的?

如何使用 LINQ 在 C# 中重构对象?

如何使用 gson 将数据保存在 json 文件中?

如何在 Go 中生成带有排序键的 JSON?

python,将Json写入文件

Rails:format.js 或 format.json,或两者兼而有之?

json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)

JSON.stringify 不会转义?

在播放框架 JsObject 中解析 Json 数组