【问题标题】:Twitter Api 1.1 not workingTwitter API 1.1 不工作
【发布时间】:2013-10-09 13:53:09
【问题描述】:

我将在我的网站上显示我最新的推文。在 tweet_json.php 上一切正常,但是当我将它们显示在我的网站上时,他给了我这个错误:

ReferenceError: listTweets 未定义

我不知道,为什么。有人可以帮帮我吗?

我的一段代码:

<script type="text/javascript" src="twitter/tweet_json.php?count=3&callback=listTweets"></script>
<script type="text/javascript">
$(document).ready(function(){
    var refreshID = setInterval(function(){
        $.getJSON('twitter/tweet_json.php?count=3', function(data) {
                listTweets(data);
        $('.twitterfeed').trigger('create');
        });
    }, 5000);
});
</script>

我正确复制/粘贴了我的 twitter 应用程序密钥。

非常感谢!

【问题讨论】:

  • listTweets() 是否在某处定义为 javascript 函数?我没有看到它,这就是您遇到的错误。
  • 你在哪里定义listTweets? ://
  • 我有两个文件。一个 tweet_json.php,没有定义像:listTweets() 之类的东西。在另一个文件 tmhOAuth.php 中,没有像 listTweets() 那样定义任何内容。 (github.com/themattharris/tmhoauth) 和 (gist.github.com/planetoftheweb/5914179)。
  • @tilldown 你修复了错误吗?我面临同样的问题..谢谢

标签: php jquery twitter web


【解决方案1】:

也许 listTweets 是在你的

中定义的
<script type="text/javascript" src="twitter/tweet_json.php?count=3&callback=listTweets"></script>

你确定 twitter/tweet_json.php 是正确的路径吗?查看您的浏览器控制台是否有 404 和 javascript 错误。

并且 我没有看到任何 jQuery 库在您调用 $(document).ready() 之前加载 这正常吗?

我们能看到你的 twitter/tweet_json.php?count=3&callback=listTweets 内容吗?

-编辑-

你只需要定义你的 listTweets 函数

function listTweets(data) {
 // You process json results here
}

-EDIT2-

function listTweets(data) {
  $.each(data, function(index) {
        console.log(data[index])
  });
}

从您的浏览器控制台观看结果。您可以使用 data[index].myfield 访问字段

【讨论】:

  • 我有两个文件。一个 tweet_json.php,没有定义像:listTweets() 之类的东西。在另一个文件 tmhOAuth.php 中,没有像 listTweets() 那样定义任何内容。 (github.com/themattharris/tmhoauth)和(gist.github.com/planetoftheweb/5914179)。我从这个网站下载了这个。我的网站上有一个 jQuery 库链接。我的 flexslider 和我自己的 writen 函数正在工作。
  • 这是一个你需要定义的函数。您告诉脚本您希望它使用您的函数“listTweets”。所以定义它!放在前面的某个地方:function listTweets(data) { //处理你的结果 }
  • 处理结果是什么意思?感谢您的帮助。
  • 您需要根据您的 json 结构结果循环遍历结果。你可以试试我的 EDIT2
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-10
  • 1970-01-01
  • 2013-06-09
  • 1970-01-01
  • 2012-08-19
  • 2014-08-06
相关资源
最近更新 更多