redouane59 / twittered

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

Unauthorized error on getUserFromUserName #314

Closed 9oTbvP8v4L closed 2 years ago

9oTbvP8v4L commented 2 years ago

Hi, I'm trying to run example from README with this piece of code

class Client(accessToken: String, accessTokenSecret: String, apiKey: String, apiSecretKey: String) : ITwitterClientV2 by
TwitterClient(TwitterCredentials.builder()
        .accessToken(accessToken)
        .accessTokenSecret(accessTokenSecret)
        .apiKey(apiKey)
        .apiSecretKey(apiSecretKey)
        .build())

class Test(private val client: Client) {
    fun test() {
        val user = client.getUserFromUserName("RedouaneBali");
        print(user)
    }
}

But it throws ERROR i.g.r.t.h.AbstractRequestHelper - (GET) Error calling https://api.twitter.com/2/users/by/username/RedouaneBali {"title":"Unauthorized","detail":"Unauthorized","type":"about:blank","status":401} - 401

Any ideas?

9oTbvP8v4L commented 2 years ago

Update: if I pass nul as access token and access token secret (so RequestHelperV2 is used), it throws ERROR i.g.r.t.h.AbstractRequestHelper - (POST) Error calling https://api.twitter.com/oauth2/token {"errors":[{"code":99,"message":"Unable to verify your credentials","label":"authenticity_token_error"}]} - 403 I think that TwitterCredentials should have one more parameter (bearerToken), possible #313?

redouane59 commented 2 years ago

Hello, Currently you cannot use only a bearer token for the library. Are you sure that your twitter dev account is valid and that your credentials are working ? Did you try to make a call from postman for example ?

9oTbvP8v4L commented 2 years ago

Hi, unfortunately, I'm not able to call any methods from the library's client. So I'm calling twitter API directly, just using your DTOs to parse results (this approach works). Yeah, I'm pretty sure the creds are valid.

redouane59 commented 2 years ago

That's really strange, you're the first user to face this problem. Could you please try another constructor ? Like using a json file ?

redouane59 commented 2 years ago

Hey, is it solved ?

kitkars commented 2 years ago

I am facing similar issue.

     twitterClient.getUserTimeline("someuser")
                     .getData()
                     .stream()
                     .map(TweetV2.TweetData::getText)
                     .forEach(System.out::println);

Error:

12:12:49.007 [main] ERROR io.github.redouane59.twitter.helpers.AbstractRequestHelper - (GET) Error calling https://api.twitter.com/2/users/someuser/tweets {"errors":[{"parameters":{"id":["someuser"]},"message":"The `id` query parameter value [someuser] is not valid"}],"title":"Invalid Request","detail":"One or more parameters to your request was invalid.","type":"https://api.twitter.com/2/problems/invalid-request"} - 400

Interestingly it works.

      Tweet tweet   = twitterClient.getTweet("1224041905333379073");
        System.out.println(tweet.getText());
        System.out.println(tweet.getCreatedAt());
        System.out.println(tweet.getLang());
        System.out.println(tweet.getLikeCount());
        System.out.println(tweet.getRetweetCount());
        System.out.println(tweet.getReplyCount());
        System.out.println(tweet.getUser().getName());
redouane59 commented 2 years ago

twitterClient.getUserTimeline("someuser") are you sure to call the function with the userid, not the username ?