最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

带有node.js的Twitter应用OAuth

运维笔记admin11浏览0评论

带有node.js的Twitter应用OAuth

带有node.js的Twitter应用OAuth

以下“应该”使用下面的message的内容发布推文,即“Lorem ipsum dolor ......”

var OAuth = require("oauth").OAuth;
const twitterer = new OAuth(    "",
                                "",
                                getContext().configuration.tasks.auto_tweet.apiAccessKey,
                                getContext().configuration.tasks.auto_tweet.apiAccessSecret,
                                // getContext().configuration.tasks.auto_tweet.apiPostKey,
                                // getContext().configuration.tasks.auto_tweet.apiPostSecret,
                                "1.0", null,"HMAC-SHA1");
// ... business logic
const message = "Lorem ipsum dolor..."
twitterer.post(     
    ".1/statuses/update.json",
    getContext().configuration.tasks.auto_tweet.apiPostKey,
    getContext().configuration.tasks.auto_tweet.apiPostSecret,
                                        ({'status': message}),
                                        "application/json",
                                        function (error, data, response2) {
                                            if(error){
                                                failedTweets ++;
                                                console.log("~~~~~~~~ Failed to send" , failedTweets, "tweets" );
                                                console.log(error);
                                            }
                                            else{ sentTweets ++; }
                                            console.log("~~~~~~~~ Sent" , sentTweets, "tweets" );
                                            setTimeout(function(){
                                                sendNextTweet();
                                            },1000);

上面的结果,在twitter应用程序仪表板中填充的键是这个错误:

`{ statusCode: 401, data: '{"errors":[{"code":89,"message":"Invalid or expired token."}]}' }`

我在这里不知所措 - 这是一个应用程序需要发布到Twitter作为自己的专用用户,它不是在验证其他用户或任何类似的东西,所以我相信callback_url是无关紧要的......在任何情况下,如果需要,我不知道callback_url会是什么。

  • 我试过交换使用的密钥s.t.构造函数使用apiPostKey / secret而post调用使用apiAccessKey / secret
  • 我已生成新密钥并使用它们更新配置。
  • 我已经验证服务器时间是否正确

此外,应用设置页面()上的“测试OAuth”按钮会生成一个包含此消息的页面“抱歉,该页面不存在!”在。然而,目前尚不清楚这告诉了我什么

回答如下:

来自:https://dev.twitter/oauth/application-only

使用仅应用程序身份验证时,您没有经过身份验证的用户的上下文,这意味着对需要用户上下文的端点(例如发布推文)的API请求将不起作用。但是,仍然可用的端点集可以具有更高的速率限制。

它将无法:

发布推文或其他资源;

我建议你尝试使用twitter的节点包:例如https://www.npmjs/package/twitter

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论