I want to use spring social to develop an twitter app which will update status and upload photos.I am not able to understand how to do Oauth authentication using Spring social.All examples I saw talks about hardcoding the accesstoken which would work only for that particular user.I dont want to hardcode anything except the app keys.
Kindly some one explain me how to do Twitter Oauth using spring social.I went through the official documentation of spring framework but got confused when I saw the other examples..
Thanks
"app keys" a.k.a.
consumer { key, secret }
pair authorizes your app to use Twitter APIs that do not require user authentication. Think about it as you app browsing a twitter website without being logged in. Hence you'd have an ability to search, get timelines, etc.. => read only.In case you'd like to post something back, you'd have to make you app do that on behalf of a real Twitter account / user. Think about someone writing a Twitter client => it can be downloaded by many different users, hence it needs two things to function properly:
consumer { key, secret }
pairaccess { token, secret }
pairIn order to get that access { token, secret } pair, you'd have to have an "OK" from that user/account.
That is where OAuth comes in => it sends the user to the confirmation page, where he clicks "OK, I allow this app to post on my behalf". This "OK" then gets converted to the
OAuthToken
that your app can use.If all you want is to post updates on behalf of yourself, then you need to approve your own Twitter app, and persist that
OAuthToken
to be used by your app.Unfortunately Twitter does not yet support OAuth 2.0, hence you'd have to do more... You'd have to do OAuth 1.0a.
Spring Social documentation describes the OAuth 1.0a flow here, where you can see the flow visually.
On order to "code" this flow using Spring Social APIs, you should first request access {token, value} pair ( there is a convenience ConnectController for it btw ):
And once it comes back (to your callback URL) you can use
OAuth1Operations
to get OAuthToken which is exactly that pair.Now, as you have all you need, you have choices:
Create a TwitterTemplate from that
OAuthToken
:Create a Twitter Connection object
Once you get the
Connection
, you might want to persist it viaConnectionRepository
as shown here, so you don't have to go through obtaining access token again.Here is Connection API.