状态 ID 元的 Twitter API getJSON - 响应为空!

发布于 2024-11-09 21:01:30 字数 706 浏览 0 评论 0原文

关于这个主题有一些类似的帖子,但它们都涉及搜索,我正在尝试做一些不同的事情。我尝试在这里应用一些逻辑来回答其他问题,但没有成功。本质上,我只是希望用户能够在文本字段中输入状态更新 ID,点击按钮,然后显示与该推文关联的所有元数据。如果我离开回调=?我收到了 URL 字符串的一部分响应,但它是空的,这显然是由于 Twitter API 实施的安全限制造成的。

这是我目前正在处理的内容:

$.getJSON("http://www.twitter.com/statuses/show/73051651728084992.json?callback=?", 
function(Data) 
{ 
  if(Data.length)
  {
    var Content = "";
    $.each(Data, function(i, Row)
    {
      alert("We Have Data");
      Content += Row;
    });
    $("#Result").append(Row);
  }
  else
    alert("No Result for that ID!");
})

返回时没有数据,但请求确实返回了 200 HTTP 响应。显然,就回调而言,我错过了一些东西,我只是不确定什么。作为一个粗略的概念证明,我将把所有数据输出到 Result div 并稍后对其进行美化。显然,首先我需要真正有一些数据可以使用!

我缺少什么?

There are some similar posts on SO about this topic but they are all dealing with search and I am trying to do something different. I have tried to apply some of the logic in answers to other questions here but w/o success. Essentially I just want users to be able to enter a status update ID into a text field, hit a button then display all meta data associated with that tweet. If I leave the callback=? part off of the URL string I get a response back but it's empty, which is obviously due to the security restrictions put in place by the Twitter API.

Here is what I am working with currently:

$.getJSON("http://www.twitter.com/statuses/show/73051651728084992.json?callback=?", 
function(Data) 
{ 
  if(Data.length)
  {
    var Content = "";
    $.each(Data, function(i, Row)
    {
      alert("We Have Data");
      Content += Row;
    });
    $("#Result").append(Row);
  }
  else
    alert("No Result for that ID!");
})

Which comes back w/ no data, yet the request does come back w/ a 200 HTTP response. Obviously I am missing something as far as the callback goes, I am just not sure what. Just as a crude proof of concept I was going to output all of the data to the Result div and pretty it up later. Obviously first things first I need to actually have some data to work with!

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人│生佛魔见 2024-11-16 21:01:30

从网址中删除 ?callback=?,然后重试。您要求 Twitter 的 api 将响应包装在回调 ? 中,这将导致无效的 JSON。另外,如有疑问,请在浏览器中手动加载 URL,以检查响应的格式是否正确。

另外,更改为此,因为 $.getJSON() 返回一个对象,而不是字符串:

if (Data) {
    var Content = "";
    ..
}

Remove the ?callback=? from the url and try again. You are asking Twitter's api to wrap the response in a callback ? which would result in invalid JSON. Also, whenever in doubt, load the url manually in your browser to examine whether the response is correctly formatted.

Also, change to this, since $.getJSON() returns an Object, not a string:

if (Data) {
    var Content = "";
    ..
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文