2016-07-05 60 views
0

我使用的節點庫回覆流中的鳴叫,當它正常工作時,鳴叫的回覆不會在時間軸上顯示爲回覆,而會顯示爲一個獨立的推文,與之前的會話沒有關聯。節點回復鳴叫並沒有真正回覆

這裏是我的代碼:

function tweetEvent(eventMsg) { 
    var replyto = eventMsg.in_reply_to_screen_name; 
    var text = eventMsg.text; 
    var from = eventMsg.user.screen_name; 

    console.log(replyto + ' ' + from); 

    if((text.indexOf('myhandle') >= 0) || (from != 'myhandle')) { 
     var reply = replies[Math.floor(Math.random() * replies.length)]; 
     var newtweet = '@' + from + ' ' + reply; 
     tweetIt(newtweet); 
    } 
} 

function tweetIt(txt) { 

    var tweet = { 
     status: txt 
    } 

    T.post('statuses/update', tweet, tweeted); 

    function tweeted(err, data, response) { 
     if (err) { 
     console.log("Something went wrong!"); 
     } else { 
     console.log("It worked!"); 
     } 
    } 
} 

回答

0

爲了回覆到使用Twitter的API的時間表顯示,你需要以下條件:

// the status update or tweet ID in which we will reply 
var nameID = eventMsg.id_str; 

此外,還需要在參數in_reply_to_status_id您的tweet status。看到更新下面的代碼,它現在應該保持對話:

function tweetEvent(eventMsg) { 
    var replyto = eventMsg.in_reply_to_screen_name; 
    var text = eventMsg.text; 
    var from = eventMsg.user.screen_name; 
    // the status update or tweet ID in which we will reply 
    var nameID = eventMsg.id_str; 


    console.log(replyto + ' ' + from); 

    if((text.indexOf('myhandle') >= 0) || (from != 'myhandle')) { 
     var reply = replies[Math.floor(Math.random() * replies.length)]; 
     var newtweet = '@' + from + ' ' + reply; 
     tweetIt(newtweet); 
    } 

    function tweetIt(txt) { 

     var tweet = { 
      status: txt, 
      in_reply_to_status_id: nameID 
     } 
} 

    T.post('statuses/update', tweet, tweeted); 

    function tweeted(err, data, response) { 
     if (err) { 
     console.log("Something went wrong!"); 
     } else { 
     console.log("It worked!"); 
     } 
    } 
} 
+0

謝謝你這一點,遺憾的是未能奏效,因爲定義的變量是使用它的功能外。我不知道該把它放在哪裏 – babusi

+0

我把'tweetIt'函數移到了'tweetEvent',它工作。謝謝 – babusi

+0

哎呀!我當時很急。我將編輯以反映變化。很高興它工作! – filmplane