簡體   English   中英

Node.Js中的Twitter API用戶時間線提取

[英]Twitter API user timeline extraction in Node.Js

我目前使用twit node.js模塊,雖然它運行良好,但我遇到了一個問題。

我希望能夠提取由我的應用程序的授權用戶制作的推文。 當我使用twit模塊在Twitter中授權時,我將發送以下數據:

var T = new Twit({
    consumer_key:         'xxxx'
    , consumer_secret:      'xxxx'
    , access_token:         'xxxx'
    , access_token_secret:  'xxxx'
});

假設我通過通行證模塊或類似的方法授權該用戶-我需要在上面替換哪些數據以獲得所需的結果?

謝謝!

登錄到Twitter,然后轉到dev.twitter.com並找到“管理您的應用程序”鏈接,它將把您重定向到apps.twitter.com,在那里您將找到“創建新應用程序”按鈕,單擊它,然后填寫表格。 創建應用程序后,轉到您創建的應用程序,然后轉到“密鑰和訪問令牌”選項卡,然后單擊“生成消費者密鑰和機密”,現在復制“消費者密鑰”“消費者機密”“訪問令牌”“訪問令牌機密”並輸入您的代碼。

如果您使用的是護照認證,請使用以下代碼獲取日志記錄用戶的“訪問令牌”和“訪問令牌密鑰”

var mongoose = require('mongoose'),
    Schema = mongoose.Schema;

var TWITTER_CONSUMER_KEY = "your consumer key got from above steps";
var TWITTER_CONSUMER_SECRET = "your consumer key secret got from above steps ";

var UserSchema = new Schema({
provider: String,
uid: String,
name: String,
image: String,
token: String,
tokenSecret: String,
created: {type: Date, default: Date.now}
});

mongoose.connect(mongooseConnectionString);
mongoose.model('User', UserSchema);

var User = mongoose.model('User');

passport.use(new TwitterStrategy({
consumerKey: TWITTER_CONSUMER_KEY,
consumerSecret: TWITTER_CONSUMER_SECRET,
callbackURL: twitterCallBackUrl
},
function(token, tokenSecret, profile, done) {
User.findOne({uid: profile.id}, function(err, user) { //check if the user profile is already     present in the database
  if(user) { //if profilie is already present then do nothing
    done(null, user);
  } else {  //else save user profile and tokens in the database
    var user = new User();
    user.provider = "twitter";
    user.uid = profile.id;
    user.name = profile.displayName;
    user.image = profile._json.profile_image_url;
    user.token = token;
    user.tokenSecret = tokenSecret;
    user.save(function(err) {
      if(err) { throw err; }
      done(null, user);
     });
   }
  })
 }
));

我想您已經是護照模塊,因此您可以自己管理其余代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM