Closed PhantomYdn closed 2 years ago
I think a big part is missing no ? How to instantiate the TwitterClient
with only a bearer token and nothing else? And then call the related endpoints.
In the same way as before: through TwitterCredentials.
https://github.com/redouane59/twittered/blob/develop/src/main/java/io/github/redouane59/twitter/TwitterClient.java#L138
Previously BearerToken
was explicitly requested with the aid of ApiKey
and ApiSecretKey
:
But if client does know BearerToken
- it can be explicitly specified in TwitterCredentials
I think it's a bit more complex.
Example running this test in ITwitterClientV2Test.java
:
@Test
public void testBearerToken(){
TwitterClient twitterClient2 = new TwitterClient(
TwitterCredentials.builder().accessToken(twitterClient.getRequestHelperV2().getBearerToken()).build());
String userName = "RedouaneBali";
User result = twitterClient2.getUserFromUserName(userName);
assertEquals(userName, result.getName());
}
This is throwing a java.lang.IllegalArgumentException: Invalid Api key
because of the ServiceBuilder
constructor expecting an api key.
It should be like this:
@Test
public void testBearerToken(){
TwitterClient twitterClient2 = new TwitterClient(
TwitterCredentials.builder().bearerToken("MY BEARER TOKEN").build());
String userName = "RedouaneBali";
User result = twitterClient2.getUserFromUserName(userName);
assertEquals(userName, result.getName());
}
That's exactly what I've done, I just got the bearer token from the other client I instantiated but even putting the String value, the exception is thrown. Just try on your side :)
Just checked with
@Test
public void testBearerToken(){
String bearerToken = "MY BEARER TOKEN";
TwitterClient twitterClient2 = new TwitterClient(
TwitterCredentials.builder()
.bearerToken(bearerToken)
.apiKey("SECRET")
.apiSecretKey("SECRET")
.build());
String userName = "RedouaneBali";
User result = twitterClient2.getUserFromUserName(userName);
assertEquals(userName, result.getName());
}
API Key and API Secret Key are needed to get Bearer Token - so if we have last one - we can just pass some value to create a service. It's a little bit ugly, but having only BearerToken is also ugly:)
API Key and API Secret Key are needed to get Bearer Token - so if we have last one - we can just pass some value to create a service. It's a little bit ugly, but having only BearerToken is also ugly:)
Yes I think it would be awesome to propose a service just with the bearer token. Would it be possible for you to implement it ?
Done - please check from your side.
Kudos, SonarCloud Quality Gate passed!
Working well, thank you so much @PhantomYdn !!!
It's needed to fix #313