如何从angular aps中的twitter api获取Twitter提要

时间:2015-04-17 06:42:51

标签: angularjs twitter

我正在使用index.html来显示供稿。          我的app.js是 -

 function randomString(length, chars) {
            var result = '';
            for (var i = length; i > 0; --i) result +=chars[Math.round(Math.random() * (chars.length - 1))];
            return result;
        }
  function twitterCallback(data){
 alert(responseJson.status.text);
  }

  var app=angular.module('store',[]);
  app.controller('indexController', function($scope, $http) {
 var unixtime=Math.round((new Date()).getTime() / 1000.0),
 nonce=randomString(32,'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
var httpMethod = 'GET',
url = 'https://api.twitter.com/1.1/statuses/home_timeline.json',
parameters = {
    oauth_consumer_key : 'AD6SEy1m3XkggNTuYw5SUl4dv',
    oauth_nonce : nonce,
    oauth_signature_method : 'HMAC-SHA1',
    oauth_timestamp : unixtime,
    oauth_token : '3131481153-I9k4ZvdnePO42lOH0EJQNQcAHoyim6XrFFzFk90',
    oauth_version : '1.0',
    screen_name:'twitterapi',
    callback:'twitterCallback'
    },
consumerSecret = 'xxxxx',
tokenSecret = 'xxxxx',

signature = oauthSignature.generate(httpMethod, url, parameters, consumerSecret, tokenSecret,
    { encodeSignature: true});

  $http.jsonp(url, {
headers: {
    'Authorization':
        'OAuth oauth_consumer_key="AD6SEy1m3XkggNTuYw5SUl4dv",' +
        'oauth_signature_method="HMAC-SHA1",' +
        'oauth_timestamp='+unixtime +
        'oauth_nonce='+nonce +
        'oauth_version="1.0",' +
        'oauth_token="3131481153-I9k4ZvdnePO42lOH0EJQNQcAHoyim6XrFFzFk90",'+
        'oauth_signature='+signature
},
params:{screen_name:'twitterapi',
}
 }).success(function (data) 
{ 
    $scope.tweets = data; 
}).error(function(data){
    console.log('error');

}) ;
});

如何连接到Twitter并定义twitter-callback?请指定如何连接twitter。 我正进入(状态 获取home_timeline.json?screen_name = twitterapi 400错误请求

0 个答案:

没有答案