redouane59 / twittered

Twitter API client for Java developers
Apache License 2.0
234 stars 64 forks source link

Can't post tweet without elevated account (using the V2 API) #421

Open shai-almog opened 1 year ago

shai-almog commented 1 year ago

I'm trying to post a tweet without the elevated permissions and getting an error since 1.x isn't supported. Looking at the code I see this line: https://github.com/redouane59/twittered/blob/develop/src/main/java/io/github/redouane59/twitter/TwitterClient.java#L803

I tried to change getRequestHelper() instead of getRequestHelperV1(). But this won't work since postRequestWithBodyJson is V1 specific so I guess we need something different here.

I tried doing something similar to:

  public Tweet postTweet(final TweetParameters tweetParameters) {
    String url  = getUrlHelper().getPostTweetUrl();
    String body = JsonHelper.toJson(tweetParameters);
    if(isV1()) {
      return getRequestHelperV1()
              .postRequestWithBodyJson(url, new HashMap<>(), body, TweetV2.class)
              .orElseThrow(NoSuchElementException::new);
    } else {
      return getRequestHelperV2().postRequest(url, body, TweetV2.class).orElseThrow(NoSuchElementException::new);
    }
  }

But it seems wrong.

It seems a bit unclear when V1 is used and when V2 is used. I'd be happy to submit a PR to the readme if I understood that logic.

redouane59 commented 1 year ago

Hey @shai-almog , if I remember well, the getRequestHelperV2() is using oAuth2 (with token), and V1 is not.

What do you mean exactly by without elevated permission ? You want to use the credentials of another user than your own account ?

shai-almog commented 1 year ago

No. I mean this

Screen Shot 2022-10-31 at 21 17 24
redouane59 commented 1 year ago

Oh OK, so you mean that with an essential account the method is not working right ?

shai-almog commented 1 year ago

Yes.

redouane59 commented 1 year ago

It looks like the essential account doesn't support the oAuth 1.0a

image

Maybe we should implement something related to OAuth 2.0 with PKCE. Honestly I'm not expert about that, if you think that you could develop it, I can try to help you.

You can also check the Oauth2PKCETest class.

shai-almog commented 1 year ago

I worked with OAuth but I can't say I'm deeply familiar with the nuances. I'll try to look into it.

redouane59 commented 1 year ago

Ok feel free to submit a pull request :)