【问题标题】:console.log says success for each call but twiiter not showing retweetsconsole.log 表示每次通话都成功,但 twiiter 没有显示转推
【发布时间】:2021-01-19 07:34:15
【问题描述】:

帮助! 我试图调用这个函数,但没有像我预期的那样工作

var T = new Twit(config);
var retweet = function() {

T.get('search/tweets', {q:'#python3, #nodejs, python3, nodejs,', count :5 }, 
function(err, data, response){
    const t_ID = data.statuses[0].id_str
    const t_ID_1 = data.statuses[1].id_str
    const t_ID_2 = data.statuses[2].id_str
    const t_ID_3 = data.statuses[3].id_str
    console.log(t_ID, t_ID_1, t_ID_2, t_ID_3)
    console.log(data)
    T.post('statuses/retweet/:id', { id: t_ID }, function (err, data, response) {
        console.log('Posted')

      })
      T.post('statuses/retweet/:id', { id: t_ID_1 }, function (err, data, response) {
        console.log('Posted_1')
        
      })
      T.post('statuses/retweet/:id', { id: t_ID_2 }, function (err, data, response) {
        console.log('Posted_2')
      })
      T.post('statuses/retweet/:id', { id: t_ID_3 }, function (err, data, response) {
        console.log('Posted_3')
      })    
} )
}
    retweet();

     setInterval(retweet, 80000);`
enter code here

console.log 显示

已发布_1 已发布 Posted_3 已发布_2

但 twitter 不转发或将转发 2 条,下次不转发 3 条。

加上代码很乱,谁能优化和解决我的错误?

【问题讨论】:

  • 您从 Post 请求中得到的实际响应是什么?他们可能会告诉你发生了什么。
  • 状态:'403 Forbidden',
  • 这个相同的脚本之前运行没有问题,有什么更好的方式来发送多个 id 的 post 请求?

标签: javascript node.js npm twitter


【解决方案1】:

我的问题是,当我在同一个调用中查询“#python3、#nodejs、python3、nodejs”时,只返回有限数量的推文,其中包括所有给定的参数,这导致我转发所有结果。

我通过每次调用仅限制 1 个参数来解决这个问题,并为我希望搜索的另一个参数创建一个新函数。

var T = new Twit(config);
var retweet = function() {

T.get('search/tweets', {q:'#python3', count :5 }, 
function(err, data, response){
    const t_ID = data.statuses[0].id_str
    console.log(t_ID)
    T.post('statuses/retweet/:id', { id: t_ID }, function (err, data, response) {
        console.log('You have RT-d post about JS')
        console.log(response.header.status)
})    
} )
}
    retweet();
     setInterval(retweet, 80000);`

控制台日志返回 tweet_id_str、成功消息(你有关于 JS 的 RT-d 帖子)和我的状态。如果状态返回 200 我成功了,如果 403 我没有。

  • 您有关于 JS 的 RT-d 帖子
    -1312731838457106432 -200 正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    相关资源
    最近更新 更多