从直接消息媒体将图像附加到 Twitter 状态

Attach image to Twitter Status from Direct Message media

大家好,我正在尝试 post 使用 Twitter https://api.twitter.com/1.1/statuses/update.json POST 请求 API 的状态。 我还想用附加图像更新状态,但图像已经在直接消息中,所以我通过使用 GET 请求获得直接消息,我得到消息的对象是这样的..

{
  type: 'message_create',
  id: 'xxxxxxxxxxxxx',
  created_timestamp: 'xxxxxxxxxxxxx',
  message_create: {
    target: { recipient_id: 'xxxxxxxxxxxxxxxx' },
    sender_id: 'xxxxxxxxxxxxxx',
    message_data: {
      text: 'This is trigger message with image,oy! https://x.xx/xxxxxxxxx',
      entities: [Object],
      attachment: {
        type: 'media',
        media: {
          id: xxxxxxxxxxxxxxx,
          id_str: 'xxxxxxxxxxxxxxx',
          indices: [ 39, 62 ],
          media_url: 'https://ton.twitter.com/1.1/ton/data/dm/xxxxx/xxxxx/gr_SQawQ.jpg',
          media_url_https: 'https://ton.twitter.com/1.1/ton/data/dm/xxxxx/xxxxx/gr_SQawQ.jpg',
          url: 'https://x.xx/xxxxx',
          display_url: 'pic.twitter.com/xxxxx',
          expanded_url: 'https://twitter.com/messages/media/xxxxxx',
          type: 'photo',
          sizes: {
            medium: [Object],
            thumb: [Object],
            large: [Object],
            small: [Object]
          }
        }
      }
    }
  }
}

我的问题是,你如何从直接消息的媒体图片中 post 带有附加图片的状态

我尝试使用该响应中的 attachment.media.idattachment.media.id_str 作为 media_ids 参数的值,但仍然出现错误 Invalid media.

const text = message.message_create.message_data.text;
const attachment = message.message_create.message_data.attachment;

const payload = {
    status: text
};
attachment && (payload.media_ids = [attachment.media.id_str]); //i've tried using id_str and id

T.post('statuses/update', payload, (error, data, response) => {
    if (!error) {
        resolve({
            message: `successfuly posting new status with DM id: ${message.id}`,
            data
        });
    } else {
        reject(error);
    };
})

谢谢

您不能通过相同的 media_id_string re-post 来自直接消息的媒体,因为它已经被“使用”了。您也不能 post URL 并显示图像,因为它对发送者和接收者是私有的。

您将需要实施 three-stage 流程:

请注意,您应该考虑重新post通过直接消息发送的图像对隐私的影响,并确保发件人知道它们可能会被重新post编辑为publically-accessible.