简体   繁体   English

使用Rest API通过URL获取媒体

[英]Fetching media by urls with Rest API

I would like to retrieve media inside statuses , but as I could read in the docs: 我想在statuss中检索媒体 ,但是正如我可以在docs中看到的那样:

For media in direct messages, media_url_https must be accessed via an authenticated twitter.com session or by signing a request with the user's access token using OAuth 1.0A. 对于直接消息中的媒体,必须通过经过身份验证的twitter.com会话或使用OAuth 1.0A使用用户的访问令牌对请求进行签名来访问media_url_https。 It is not possible to directly embed these images in a web page 无法将这些图像直接嵌入网页中

Now my question is, how to do that kind of request using Java API? 现在我的问题是,如何使用Java API进行此类请求? or however what is the correct request with RestAPI, using App only auth? 或然而,使用仅应用程序身份验证的RestAPI的正确请求是什么?

another question: what is the difference for media in direct messages and media shared in Tweets? 另一个问题:直接消息中的媒体和推文中共享的媒体有什么区别? how can I see the difference inside json object representing a status? 如何查看表示状态的json对象内部的差异?

what is the difference for media in direct messages and media shared in Tweets? 直接消息中的媒体与推文中共享的媒体有什么区别?

If an image is posted to a Twitter timeline, any Internet user can see it. 如果将图像发布到Twitter时间轴,则任何Internet用户都可以看到它。 For example on this Tweet the image is available to anyone, whether or not they're logged into Twitter. 例如, 在此Tweet上,任何人都可以使用该图像,无论他们是否已登录Twitter。 See https://pbs.twimg.com/media/CSGwFynWoAA2GGG.jpg 参见https://pbs.twimg.com/media/CSGwFynWoAA2GGG.jpg

If an image is posted into a Direct Message, it is only possible for the sender and receiver to see the image. 如果将图像发布到直接消息中,则发送者和接收者只能看到该图像。 In order to enforce that, the user must either be signed in to their Twitter account, or send a signed request via an app. 为了强制执行此操作,用户必须登录其Twitter帐户,或通过应用发送已签名的请求。

For example, this image can only be seen by me & the person I sent it to https://ton.twitter.com/i/ton/data/dm/639737026624024579/639737026682691584/tg-4St-1.jpg 例如,此图像只能由我和我发送给https://ton.twitter.com/i/ton/data/dm/639737026624024579/639737026682691584/tg-4St-1.jpg的人看到

how can I see the difference inside json object representing a status? 如何查看表示状态的json对象内部的差异?

The only difference (other than the API call you used to get the data) is the URl of the media. 唯一的区别(除了用于获取数据的API调用之外)是介质的UR1。 In a DM it starts with ton. 在DM中,它以ton.开始ton. eg 例如

media_url": "https://ton.twitter.com/1.1/ton/data/dm/......

Whereas in a normal Tweet, it will look like eg 而在正常的Tweet中,它看起来像

"media_url": "http://pbs.twimg.com/media/.......

Now my question is, how to do that kind of request using Java API? 现在我的问题是,如何使用Java API进行此类请求? or however what is the correct request with RestAPI, using App only auth? 或然而,使用仅应用程序身份验证的RestAPI的正确请求是什么?

If the user is already logged in to Twitter, they will be able to download the image. 如果用户已经登录到Twitter,则可以下载该图像。 For example, if you have written a web-app and the browser already contains the Twitter cookies etc. 例如,如果您编写了一个Web应用程序,并且浏览器已经包含Twitter cookie等。

If not - or you're using an app - you will need to sign the request on the user's behalf. 如果不是(或者您使用的是应用),则需要代表用户对请求进行签名。

For REST - you need to send OAuth headers with the request. 对于REST-您需要随请求发送OAuth标头。 There's example code in the Twitter documentation Twitter文档中示例代码

The extra header will look something like 多余的标题看起来像

Authorization: OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318622958", oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", oauth_version="1.0"

For Java, I'd suggest you take a look at how Twidere does it . 对于Java,建议您看看Twidere的工作方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM