【问题标题】:Accessing JSON Data with AngularJS and Twitter Streaming API使用 AngularJS 和 Twitter 流 API 访问 JSON 数据
【发布时间】:2013-03-18 15:01:10
【问题描述】:

首先,我正在开发我的 tweetganic 应用程序,该应用程序需要访问 twitter 流 API、客户端并通过 AngularJS 管理结果。

这是我的 Coffeescript/JS:

@AccountCtrl = ["$scope", "$http", ($scope, $http) ->
  $scope.doSearch = ->
    $scope.twitter = $http.post("https://tweetganic:password@stream.twitter.com/1.1/statuses/filter.json",
        track: $scope.searchTerm)
]

当我单击运行 doSearch() 的按钮时,我在控制台中收到此错误:

OPTIONS https://stream.twitter.com/1.1/statuses/filter.json 401 (Unauthorized) angular.js:9231
 (anonymous function) angular.js:9231
 sendReq angular.js:9066
 $http angular.js:8857
 $http.(anonymous function) angular.js:9012
 $scope.doSearch twitter_accounts.js:9
 (anonymous function) angular.js:6299
 (anonymous function) angular.js:12880
 Scope.$eval angular.js:7994
 Scope.$apply angular.js:8074
 $delegate.__proto__.$apply localhost:500
 (anonymous function) angular.js:12879
 (anonymous function) angular.js:1959
 forEach angular.js:134
 eventHandler angular.js:1958
XMLHttpRequest cannot load https://stream.twitter.com/1.1/statuses/filter.json. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.

为什么我不知道如何通过 Angular 打开与流式 Twitter api 的连接?

存储库:https://github.com/brianpetro/tweetganic

【问题讨论】:

    标签: javascript json angularjs coffeescript


    【解决方案1】:

    这是一个 CORS 问题。 twitter 流 api 不支持 CORS。

    您可以使用代理 https://github.com/gr2m/CORS-Proxy

    【讨论】:

      猜你喜欢
      • 2016-02-03
      • 1970-01-01
      • 2011-06-11
      • 2013-09-08
      • 2015-03-06
      • 2011-12-26
      • 1970-01-01
      • 2020-10-12
      • 2018-12-10
      相关资源
      最近更新 更多