代码之家  ›  专栏  ›  技术社区  ›  João Armando

如何在Twitter API上启用增强的URL扩展?

  •  0
  • João Armando  · 技术社区  · 6 年前

    我正在检索tweet并向用户显示。

    enter image description here

    请参阅我希望得到的响应示例

    {
       "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

    这是我用来检索tweet的代码 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扩展来接收对象吗 解开

    1 回复  |  直到 5 年前
        1
  •  7
  •   Terence Eden    6 年前

    Premium enrichments是一些数据API的响应负载中包含的附加元数据。它们仅在付费订阅计划中可用。

    https://developer.twitter.com/en/docs/tweets/enrichments/overview

    因此,您需要获得高级API订阅才能获得丰富的内容。很抱歉