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

问题描述

大家好,我试图使用Twitter <!--this will do--> <body style="display: grid; align-content: end; height: 100vh; margin: 0;"> <footer> <div> <a href="https://stackoverflow.com/users/14248176/achyuta-pataki"> <img src="stack.png" height="40px" width="40px"> </a> &nbsp; <a href="https://github.com/achyutap"><img src="github.png" height="40px" width="40px"></a> &nbsp; <a href="mailto:achyutapataki@gmail.com"><img src="email.png" height="40px" width="40px"></a> </div> </footer> </body> POST请求API发布状态。 我还想用附加的图像更新状态,但是该图像已经在直接消息中,因此我可以通过使用GET请求获得直接消息,并获得消息的对象,如下所示。

https://api.twitter.com/1.1/statuses/update.json

我的问题是,如何从上面的直接消息的媒体图像中发布带有附件图像的状态

我尝试使用该响应中的{ 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.id作为attachment.media.id_str参数的值,但仍然收到错误media_ids

Invalid media.

谢谢

解决方法

您无法通过同一media_id_string通过直接消息重新发布媒体,因为该媒体已被“使用”。您也不能发布URL并显示图像,因为它是发送方和接收方专用的。

您将需要执行三个阶段的过程:

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...