i must use setOauthConsumer(cons key, cons secret) then, after that in the app I must use get getOAuthAccessToken to get oauth access token. But i'm alredy have this(!), so i can use acces token and secret directly, or what?
We need the following 4 values for every request to twitter API
:
- Consumer key
- Consumer Secret
- Access Token
- Access Token Secret
You already have the following values:
- Consumer key
- Consumer Secret
Access Token & Access Token Secret are fetched in following two ways:
Case 1: Configuration required for app-only auth, to fetch the twitter feeds even without Logging in to twitter account.
As you have not logged in, the twitter4j
gives the OAuth2Token
(access token and token secret) using getOAuth2Token();
Then you use these values in your configuration of Twitter
instance. No need to store these values. You can get them using getOAuth2Token()
for every request.
Case 2: When you login using your credentials.
In this case, the request is sent to Twitter API
to get access token and access token secret (values are generated at the time of registering your application on Twitter
).
Once you get these values, store it in SharedPrefernces
and use them in subsequent requests. No need to request them again and again.
I hope this helps you.