Javascript Twitter机器人图片发布错误
好的,通过这些教程,我在设置twitterbot时玩得很开心,在发布图片之前我没有遇到任何问题。我一直在关注这些教程:并且一直停留在15.6()上,我们在那里发布图像。这需要一段时间来观看所有的内容,但你可能可以跳过简单的推文,关注回复视频。现在,我理解了这个家伙80%的意思,因为我对JS有点陌生,而你们中的一些人比我更有经验,所以我的一些代码有点重复,但我想确保一切都正常运行Javascript Twitter机器人图片发布错误,javascript,node.js,twitter,npm,youtube,Javascript,Node.js,Twitter,Npm,Youtube,好的,通过这些教程,我在设置twitterbot时玩得很开心,在发布图片之前我没有遇到任何问题。我一直在关注这些教程:并且一直停留在15.6()上,我们在那里发布图像。这需要一段时间来观看所有的内容,但你可能可以跳过简单的推文,关注回复视频。现在,我理解了这个家伙80%的意思,因为我对JS有点陌生,而你们中的一些人比我更有经验,所以我的一些代码有点重复,但我想确保一切都正常运行 var imageTweet = function(txt) { var tweet = {
var imageTweet = function(txt) {
var tweet = {
status:txt
}
//This is for uploading the image to twitter but not actually tweeting it
//Might want to define the b64_img
var b64_img = 0;
var imageProcessing = function(){
var filename = "dankykang.jpg";
var params_img = {
encoding:'base64'
}
b64_img = fs.readFileSync(filename, params_img)
}
imageProcessing();
var upload_params = {
media_data: b64_img
}
T.post('media/upload', upload_params, tweeted_img);
function upload_img(err, data, response){
//This part does the tweet
var id = data.media_id_string;
var tweet = {
//for text in the image tweet
status:"testing a new way to tweet an image...",
//This calls the image from the imageProcessing function
media_ids:[id]
}
T.post('statuses/update', tweet, imgstatustweeted);
function imgstatustweeted(){
if (err){
console.log("The status didn't work")
} else {
console.log("Status worked")
}
}
imgstatustweeted();
}
upload_img();
function tweeted_img(err, data, response){
if (err){
console.log("Image not posted");
} else {
console.log("Image posted");
}
}
tweeted_img();
}
imageTweet();
我跟随他的大部分步骤,有些名字的改变,我认为我没有错过任何东西。。。但是当我运行bot.js时,它总是在data.media\u id\u字符串上给我一个错误;[上面的var tweet={…}下面的函数upload_img(…)]
它表示TypeError:无法读取未定义的属性“media\u id\u string”。但根据我下面的教程,我认为这必须与建立的npm有关。所以我不知道为什么在他这一方运行良好,但在我这一方运行不良好。如果我没有弄错的话,这不是语法问题。您调用的是
upload\u img()
,没有必要的参数,包括data
。使用upload\u img(data)
或upload\u img(err,data,response)
调用它不起作用,它给出了与数据未定义相同的错误。这是因为data
未定义。所以我将其定义为data=0;不,你发布的代码似乎依赖于数据
是T.post('media/upload',upload_params,tweet_img')的结果代码>呼叫<代码>数据
很重要。您的函数需要数据。媒体\u id\u string
设置为有效且有意义的内容(可能是您在媒体/上传
调用中创建的媒体项的id)才能工作。您需要开始阅读和理解正在使用的代码。您正在调用upload\u img()
,但没有必需的参数,包括data
。使用upload\u img(data)
或upload\u img(err,data,response)
调用它不起作用,它给出了与数据未定义相同的错误。这是因为data
未定义。所以我将其定义为data=0;不,你发布的代码似乎依赖于数据
是T.post('media/upload',upload_params,tweet_img')的结果代码>呼叫<代码>数据
很重要。您的函数需要数据。媒体\u id\u string
设置为有效且有意义的内容(可能是您在媒体/上传
调用中创建的媒体项的id)才能工作。您需要开始阅读和理解正在使用的代码。