nodejs twitter api从请求主体获取oauth访问令牌和秘密

问题描述

我正在编写一个脚本,以从Twitter获取用户的主页时间轴。

当前,我正在使用开发者帐户本身的访问令牌和机密,并且只能获得该用户的家庭时间表。

我希望前端让其他用户授权此应用,并检索相应的令牌和机密,然后在碰到端点时将其传递给服务器。

c=4
r=2
o=2
a=3
ccccrrooaaa

这里我假设前端是处理针对我们应用的用户身份验证,并在到达const { TWITTER_CONSUMER_KEY,TWITTER_CONSUMER_SECRET,TWITTER_ACCESS_TOKEN,TWITTER_ACCESS_TOKEN_SECRET,} = process.env as any; class TwitterFeed { public path = "/tweet"; public router = express.Router(); // this instance is used for app-auth context only private T = new Twit({ consumer_key: TWITTER_CONSUMER_KEY,consumer_secret: TWITTER_CONSUMER_SECRET,access_token: TWITTER_ACCESS_TOKEN,access_token_secret: TWITTER_ACCESS_TOKEN_SECRET,}); .... .... private homeTimeline = async (request:Request,reponse:Response,next: NextFunction) => { try { // create new Twit instance for this one.. // with request ACCESS_TOKEN and SECRET const tw = new Twit({ consumer_key: TWITTER_CONSUMER_KEY,// access token from post body access_token: request.body.access_token,// access token secret from post body access_token_secret: request.body.access_token_secret,}); const tweets: any = await tw.get('statuses/home_timeline',{ count: 20 }); const data = tweets.data.map((tweet: any) => { return { created_at: tweet.created_at,id_str: tweet.id_str,text: tweet.text,entities: tweet.entities,retweet_count: tweet.retweet_count,favorite_count: tweet.favorite_count }; }); reponse.send(data); } catch (error) { next(error); } } 的端点时发送access_tokenaccess_token_secret值。

这是正确的做法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...