Domanda

There is somthing that i can't understood. I'm trying to writte a simple app in android to post twitt's into my account. I registered my app in dev.twitter. There i got an api(consumer) key/secret, and access token/access secret pairs. BUT, as in the example, 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?

p. s. i know twitter4j.org examples, and i can use other resources, but i cant find the answer, so i'm posting here

È stato utile?

Soluzione

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:

  1. Consumer key
  2. Consumer Secret
  3. Access Token
  4. Access Token Secret

You already have the following values:

  1. Consumer key
  2. 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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top