【问题标题】:Attach image to Twitter Status from Direct Message media从直接消息媒体将图像附加到 Twitter 状态
【发布时间】:2021-01-08 17:58:39
【问题描述】:

大家好,我尝试使用 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]
          }
        }
      }
    }
  }
}

我的问题是,您如何发布带有附加图片的状态,来自上述直接消息的媒体图片??

我尝试使用来自该响应的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);
    };
})

谢谢

【问题讨论】:

    标签: javascript api twitter twitter-oauth


    【解决方案1】:

    您不能通过同一 media_id_string 从直接消息中重新发布媒体,因为它已被“使用”。您也不能发布 URL 并显示图像,因为它对发送者和接收者是私有的。

    您将需要实施一个三阶段流程:

    请注意,您应该考虑重新发布通过私信发送的图像对隐私的影响,并确保发件人知道它们可能会被重新发布为可公开访问。

    【讨论】:

    • 是的,发件人之前也被告知,dm 将被重新发布为可公开访问
    猜你喜欢
    • 2017-07-04
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    • 2020-10-14
    • 2012-12-03
    • 2011-09-17
    相关资源
    最近更新 更多