如何获取我在 Twitter V2 中关注的用户的推文?
How to get tweets of users I am following in Twitter V2?
在 nodeJS 中向我自己的身份验证用户 users/{id}/tweets
发出 GET
请求并使用 V2 Twitter api、returns 仅 条由我自己的身份验证用户 id 发布的推文。
我需要什么?
获取我自己发布的所有推文以及我关注的用户在我的时间轴中显示的所有推文。
基本上,与 Twitter V1 GET statuses/home_timeline
中的结果相同
我怎样才能在 V2 中获得这个?
index.js
const express = require("express");
const app = express();
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(express.json()); // for parsing application/json
const Twit = require("twitter-lite");
const config = require("./config");
const client = new Twit(config.appConfig);
function getTimeLineTweetsInV2() {
return new Promise(async (resolve, reject) => {
try {
let result = await client.get("users/tweets/1497521946694717448");
resolve(result);
} catch (error) {
console.log("errorrrrrrrrrr is", error);
reject(error);
}
});
}
(async function BotMain() {
let tweetsReceived = await getTimeLineTweetsInV2();
console.log(tweetsReceived);
})();
app.listen(3000, () => {
console.log("listeing on port 3000");
});
config.js
const dotenv = require("dotenv");
const path = require("path");
const ENV_FILE = path.join(__dirname, ".env");
dotenv.config({ path: ENV_FILE });
const appConfig = {
//define subdomain of twitter api URL e.g. api.twitter.com, streams.twitter.com
version: "2",
extension: false,
consumer_key: process.env.apikey,
consumer_secret: process.env.apisecret,
access_token_key: process.env.accesstoken,
access_token_secret: process.env.accesstokensecret,
};
module.exports = {
appConfig,
};
package.json
{
"name": "twitter_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.0",
"express": "^4.17.3",
"path": "^0.12.7",
"twitter-lite": "^1.1.0"
}
}
v2 中没有与主时间轴 API 对应的内容 - 还。这是on the roadmap。您需要使用 v1.1 API,或者,请耐心等待,直到新版本可用。
在 nodeJS 中向我自己的身份验证用户 users/{id}/tweets
发出 GET
请求并使用 V2 Twitter api、returns 仅 条由我自己的身份验证用户 id 发布的推文。
我需要什么?
获取我自己发布的所有推文以及我关注的用户在我的时间轴中显示的所有推文。
基本上,与 Twitter V1 GET statuses/home_timeline
我怎样才能在 V2 中获得这个?
index.js
const express = require("express");
const app = express();
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(express.json()); // for parsing application/json
const Twit = require("twitter-lite");
const config = require("./config");
const client = new Twit(config.appConfig);
function getTimeLineTweetsInV2() {
return new Promise(async (resolve, reject) => {
try {
let result = await client.get("users/tweets/1497521946694717448");
resolve(result);
} catch (error) {
console.log("errorrrrrrrrrr is", error);
reject(error);
}
});
}
(async function BotMain() {
let tweetsReceived = await getTimeLineTweetsInV2();
console.log(tweetsReceived);
})();
app.listen(3000, () => {
console.log("listeing on port 3000");
});
config.js
const dotenv = require("dotenv");
const path = require("path");
const ENV_FILE = path.join(__dirname, ".env");
dotenv.config({ path: ENV_FILE });
const appConfig = {
//define subdomain of twitter api URL e.g. api.twitter.com, streams.twitter.com
version: "2",
extension: false,
consumer_key: process.env.apikey,
consumer_secret: process.env.apisecret,
access_token_key: process.env.accesstoken,
access_token_secret: process.env.accesstokensecret,
};
module.exports = {
appConfig,
};
package.json
{
"name": "twitter_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.0",
"express": "^4.17.3",
"path": "^0.12.7",
"twitter-lite": "^1.1.0"
}
}
v2 中没有与主时间轴 API 对应的内容 - 还。这是on the roadmap。您需要使用 v1.1 API,或者,请耐心等待,直到新版本可用。