Domanda

I want to allow users to sign up and login to my Java web app using their Twitter account. The only information I need from their Twitter account is their name (or Twitter username if a name has not been provided) and their email address.

I came across the scribe OAuth library that provides an example of how to use it to authenticate with Twitter from a console app. However, I can't figure out how to adapt this to a web app. I don't think I can use this example "as is" because it contains code like:

Scanner in = new Scanner(System.in);

that won't work from a webapp. Also, I can't see how to retrieve the user's name and email address once the authentication has completed.

If someone could point me towards a complete example of how to authenticate with Twitter (using OAuth) from a Java webapp and retrieve the user's name and email, that would be great. The example doesn't necessarily have to use scribe, though the less code I have to write myself, the better.

È stato utile?

Soluzione

You need to have an endpoint in you application that receives the verifier.

If you go the OOB way, like in the example, the client will have to perform the call to your endpoint manually:

curl http://example.com?verifier=123456

If you use callback like this:

Service service = new ServiceBuilder().callback("http://example.com"). //rest of the config

Twiiter will perform the call itself and redirect the user browser to your endpoint.

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