问题描述
大家好,我试图使用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>
<a href="https://github.com/achyutap"><img src="github.png"
height="40px"
width="40px"></a>
<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并显示图像,因为它是发送方和接收方专用的。
您将需要执行三个阶段的过程:
- 将图像从“直接消息”下载到本地文件。您将need to use OAuth user authentication执行此操作。
- upload the media作为Twitter上的新实体,并获取新的
media_id_string
- 发布new Tweet,并附加
media_id_string
。
请注意,您应该考虑重新发布通过Direct Message发送的图像的隐私含义,并确保发件人知道它们可能被重新发布为可公开访问。