我正在创建一个使用twitter API的应用程序。 我正在检索该推文并向用户显示。
在阅读Twitter的api文档时,我发现了一个名为“增强的URL丰富”的东西,其中包括链接元数据,其中包含图像URL,标题,描述。
查看我想要获得的回复示例
{"urls": [
{
"url": "https://exampleurl.com/D0n7a53c2l",
"expanded_url": "http://exampleurl.com/18gECvy",
"display_url": "exampleurl.com/18gECvy",
"unwound": {
"url": "https://www.youtube.com/watch?v=oHg5SJYRHA0",
"status": 200,
"title": "RickRoll'D",
"description": "http://www.facebook.com/rickroll548 As long as trolls are still trolling, the Rick will never stop rolling."
},
"indices": [
62,
85
]
}
]
}
注意对象展开,其中包含了我所需要的一切。 You can find the above response in the documentation here:
And more about Enhanced URLs enrichment here
我正在通过端点GET statuses/user_timeline 检索推文
这是我使用Twitter4j检索推文的代码
final ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(Constant.getConsumerKeyTwitter());
cb.setOAuthConsumerSecret(Constant.getConsumerSecretTwitter());
cb.setOAuthAccessToken(tokenUser);
cb.setOAuthAccessTokenSecret(secretTokenUser);
cb.setTweetModeExtended(true);
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
List<Status> statuses = twitter.getUserTimeline(userIDToGetTweets);
使用此代码,我无法收到展开的对象。
您知道我如何启用增强的URL扩充功能来接收对象展开
答案 0 :(得分:1)
遗憾的是,这仅适用于付费客户。
高级充值是一些数据API的响应有效负载中包含的附加元数据。它们仅在付费订阅计划中可用。
https://developer.twitter.com/en/docs/tweets/enrichments/overview
因此,您需要获得高级API订阅才能获得丰富的功能。抱歉。