Twitter api v1 在发送 post 时授权 media_ids 出现问题
Twitter api v1 problem with authorization of media_ids while sending a post
我正在构建一个 Twitter 机器人,它可以发送包含媒体的 Twitter post。我可以毫无问题地发送一个只有文本的 post。但是当我尝试将 media_ids 添加到 post:
时会抛出以下错误
[ { code: 32, message: 'Could not authenticate you.' } ]
这是我发送 Twitter 的函数 post:
const axios = require('axios')
const fs = require('fs')
const Path = require('path')
const Twitter = require('twitter')
require('dotenv').config()
const client = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
})
async function sendTwitterPost() {
return new Promise(async (resolve, reject) => {
try {
const contents = await fs.promises.readFile('./temp/image.png', {encoding: 'base64'})
console.log("Got the image, uploading image to twitter...")
const res = await client.post('media/upload', {
media_data: contents,
media_category: 'tweet_image'
})
console.log(res.media_id + " Image uploaded, sending twitter post...")
let mediaIds = []
mediaIds.push(res.media_id)
await client.post('statuses/update', {
status: 'New event occured!',
media_ids: mediaIds
})
resolve("Twitter post successfully sent")
}
catch(err){
console.log(err)
reject("Error while sending twitter post")
}
})
}
我的令牌有读写权限,正如我所说的,我可以发送一个只有文本的 post。我也有提升的访问权限。
我通过更改
修复了它
let mediaIds = []
mediaIds.push(res.media_id)
await client.post('statuses/update', {
status: 'New event occured!',
media_ids: mediaIds
})
至
await client.post('statuses/update', {
status: 'New event occured!',
media_ids: res.media_id_string
})
twitter api v1 with twitter package 的 media_ids 字段似乎需要字符串。
我正在构建一个 Twitter 机器人,它可以发送包含媒体的 Twitter post。我可以毫无问题地发送一个只有文本的 post。但是当我尝试将 media_ids 添加到 post:
时会抛出以下错误[ { code: 32, message: 'Could not authenticate you.' } ]
这是我发送 Twitter 的函数 post:
const axios = require('axios')
const fs = require('fs')
const Path = require('path')
const Twitter = require('twitter')
require('dotenv').config()
const client = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
})
async function sendTwitterPost() {
return new Promise(async (resolve, reject) => {
try {
const contents = await fs.promises.readFile('./temp/image.png', {encoding: 'base64'})
console.log("Got the image, uploading image to twitter...")
const res = await client.post('media/upload', {
media_data: contents,
media_category: 'tweet_image'
})
console.log(res.media_id + " Image uploaded, sending twitter post...")
let mediaIds = []
mediaIds.push(res.media_id)
await client.post('statuses/update', {
status: 'New event occured!',
media_ids: mediaIds
})
resolve("Twitter post successfully sent")
}
catch(err){
console.log(err)
reject("Error while sending twitter post")
}
})
}
我的令牌有读写权限,正如我所说的,我可以发送一个只有文本的 post。我也有提升的访问权限。
我通过更改
修复了它let mediaIds = []
mediaIds.push(res.media_id)
await client.post('statuses/update', {
status: 'New event occured!',
media_ids: mediaIds
})
至
await client.post('statuses/update', {
status: 'New event occured!',
media_ids: res.media_id_string
})
twitter api v1 with twitter package 的 media_ids 字段似乎需要字符串。