简体   繁体   English

从Twitter以XML检索user_timeline

[英]Retrieving user_timeline from Twitter in XML

I'm writing a simple app in HTML and Javascript. 我正在用HTML和Javascript编写一个简单的应用程序。 I'm trying to retrieve my user_timeline via jQuery's .ajax() method. 我正在尝试通过jQuery的.ajax()方法检索user_timeline。 The problem is that I want to retrieve my timeline in XML but I'm keep failing with this simple task. 问题是我想用XML检索时间轴,但这个简单的任务一直失败。 Here's my code: 这是我的代码:

$.ajax({
        type: 'GET',
        dataType: 'xml',
        url: 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=stepanheller',
        success: function(data, textStatus, XMLHttpRequest) {
            console.log(data);
        },
        error: function(req, textStatus, error) {
            console.log('error: '+textStatus);
        }

});

Weird thing is that when I try exactly the same thing but with JSON instead of XML then the script works. 奇怪的是,当我尝试使用JSON而不是XML进行完全相同的尝试时,脚本可以工作。

$.ajax({
        type: 'GET',
        dataType: 'jsonp',
        url: 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=stepanheller',
        success: function(data, textStatus, XMLHttpRequest) {
            console.log(data);
        },
        error: function(req, textStatus, error) {
            console.log('error: '+textStatus);
        }

});

Can you give me some hints what I'm doing wrong with the request? 您能否给我一些提示,说明我在做错什么? I know that I'm using old version of API but I won't deal with OAuth right now. 我知道我使用的是旧版的API,但现在不会处理OAuth。 Thanks. 谢谢。

It is generally impossible to send a Cross-domain ajax request. 通常不可能发送跨域Ajax请求。 It's the general rule. 这是一般规则。

JsonP is the classic way to work around this limitation, and there is no equivalent for Xml according to my knowledge. JsonP是解决此限制的经典方法,据我所知,没有Xml的等效方法。 Depending on your browser compatibility constraints, you can use XHR2 to achieve this. 根据您的浏览器兼容性限制,可以使用XHR2来实现此目的。

Otherwise, the only solution is to set up a server proxy. 否则,唯一的解决方案是设置服务器代理。

Client --Ajax--> Your server --HttpRequest--> Twitter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM