Everyone (and especially Yasuke),
I’m attempting to follow the instructions here…
… but failing due to the persistent nature of Twitter4J and my use of it in a web services endpoint.
On the first call from a user to the backend to startTwitterAuthentication (my method), everything works fine as I instantiate the Twitter object, set the consumer key and secret, and get request token. I retrieve the redirect url and sent the user there where the PIN number appears (which my application can programmatically extract). So far so good…
The trouble is with the second request. I get: “consumer key/secret pair already set” The Twitter object doesn’t want to be instantiated again even though it appears to be a a local variable in my scope. This would be easy to skip with an “if (key/secret pair is already set)” conditional, but I can’t find such a function within the Twitter class. Please help me understand where I’m going wrong on this. I’ve tried to move the Twitter object into a more global scope, but I get errors there, too (which, unfortunately, I can’t remember – exhausted from doing battle with Twitter API all day).
My ultimate goal is to get access tokens for users, put them in their cookies and have the users make twitter search api requests within my frontend. This is SUPER easy right now using API 1.0 because no authentication is required. Hence, the need for twitter4j.
In addition to the above problem, I’m uncertain how to use twitter4j.properties for the key/secret. I’ve got the twitter4j.properties file in the right place, but the example code above only shows how to use them hardcoded with twitter.setOAuthConsumer(“FasdfasdfasdfadsfasdfasfaQ”, “2pBLAHBLAHBLAHBALHBLHABHL4”). Is there a way to instantiate the Twitter object and tell it “use the properties file”?
Thanks for your help.