使用 scribejava 使用 JSON 正文制作 Twitter OAuth1 PUT 请求

Making Twitter OAuth1 PUT request with JSON body with scribejava

我想打电话给 this twitter v2 endpoint to hide a tweet using OAuth1 and ScribeJava

这是我试过的方法

val service = ServiceBuilder(apiKey)
        .apiSecret(apiSecret)
        .build(TwitterApi.instance())

    val url = "https://api.twitter.com/2/tweets/${tweetId}/hidden"

    val oauth1 = OAuth1AccessToken(token,secret)
    val request = OAuthRequest(Verb.PUT, url)
    request.setPayload("{ \"hidden\": true }")

    service.signRequest(oauth1, request)
    val response = service.execute(request)

当我尝试返回 400 Bad Request 时,正确的方法是什么?

你的问题的原因可能与你试图隐藏一条你没有能力隐藏的推文有关。请注意推文必须遵守的限制才能被隐藏。它在 Twitter developer documentation:

Step three: Find a Tweet ID to hide 部分中说明

The hide replies endpoint can hide or unhide replies on behalf of an authorized user. Because we are using the Access Tokens related to your user profile in this example, you will be able to hide replies from users who participate in a conversation started by you. Similarly, if you were using Access Tokens that belong to another user that authorized your app, you would be able to moderate replies to any conversations started by that account.

Ask a friend to reply to a Tweet (let them know you're testing hide replies) or reply to any of your Tweets from a test account. Click on that reply, then copy the numeric part of its URL. That will be the Tweet ID we will hide.