我使用了这个链接 https://dev.twitter.com/apps 我按照了这个程序,获得了消费者密钥,消费者密钥,访问令牌密钥,访问令牌密钥详细信息。我把它放在我的代码中。我在localhost中运行它显示** twitter.verifyCredentials不是一个函数。**我附上代码可以让任何人告诉我代码中的问题是什么。提前谢谢......
var twitter=require("twitter");
var tweeter = new twitter(
{
consumer_key:'xyz',
consumer_secret:'abx',
access_token_key:'asd',
access_token_secret:'www'
});
app.get('/twitterCheck', function (req, res) {
twitter.verifyCredentials(function (error, data)
{
res.send("Hello, " + data.name + ". I am in your twitters.");
});
});
app.listen(8086,function()
{
console.log("port is listen on 8086");
});
答案 0 :(得分:0)
这是来自node-twitter-api
包。尝试使用node-twitter-api
,这将有效:
const express = require('express')
const app = express()
const twitterAPI = require('node-twitter-api');
const twitter = new twitterAPI({
consumerKey: '*****',
consumerSecret: '******',
});
const accessToken = "***********";
const accessTokenSecret = "***********";
const params = {};
app.get('/twitterCheck', function (req, res) {
twitter.verifyCredentials(accessToken, accessTokenSecret, params, function (error, data, response) {
if (error) {
console.log(error);
} else {
console.log(data["screen_name"]);
}
});
});
app.listen(8086, function () {
console.log("port is listen on 8086");
});