在Axois中获取推文和Auth标头

时间:2018-10-01 07:13:39

标签: node.js twitter axios twitter-oauth

从时间轴获取用户推文-使用Axios调用Twitter API https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html

其无法授权标题

这是我的代码

const axios = require('axios');
require('dotenv').config();


var apiurl = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=nodejs&count=5';

const client = {
    consumer_key: process.env.CONSUMERKEY,
    consumer_secret: process.env.CONSUMERSECRET,
    bearer_token: process.env.BEARERETOKEN
};

async function go() {

    try {
        await new Promise(resolve => setTimeout(resolve, 1000));
        const wes = await axios({
            method: 'post',
            auth: client,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            url: apiurl
        });
        var getweets = wes.data;
        console.log(getweets);

        const group = getweets.tweets.map(g => [
            g.text
        ]);

        var data = JSON.stringify(group, null, 2);
        console.log(data.replace(/\[|\]|"|,/g, ''));

    } catch (e) {
        console.error(e);
    }
}
go();

我想获取用户的时间轴推文

0 个答案:

没有答案