使用Twitter中的node.js API回复Twitter的直接消息

时间:2017-03-02 07:10:59

标签: javascript node.js twitter

我正在使用twit npm包来阅读直接消息

var stream = T.stream('user', { stringify_friend_ids: true })
stream.on('direct_message', function (directMsg) {
console.log(directMsg)
}

我想回复收到的directMsg,是否有任何方法调用twit可用于实现或推荐达到相同的任何其他nodejs包。

2 个答案:

答案 0 :(得分:1)

无法提供确切的代码解决方案,但方法是实现以下步骤

  1. USER_ID对象
  2. 获取directMsg属性
  3. 使用Twit Rest API方法T.post(path, [params], callback)通过USER_ID
  4. 向用户发送直接消息
  5. 使用Twitter API documentation了解发送直接消息所需的内容,您需要正确提供文档中的参数
  6.   

    enter image description here

    所以代码看起来像这样

    T.post("direct_messages/new", {
        user_id: USER_ID, // USER_ID is parameter from directMsg object
        text: 'YOUR_REPLY'
    });
    

    希望它会对你有所帮助。

答案 1 :(得分:0)

即使我遇到它,这是你必须做的。 收听user的{​​{1}}信息流并检索direct_messagesender.screen_name并验证它不相等+您需要{@ 1}},如上面@RashadIbrahimov所述。

recipient.screen_name

并打电话给它 sender.id

相关问题