I'm creating a desktop Twitter client in Java using the twitter4j library. I've got my app's API key and secret. Now after I obtain the request token I get the authorization URL which the user has to open in a web browser, login from his account, allow access to the app, and retrieve the access pin. After he enters this pin in the app, the app gets permanent access to the users account. Is there a way in Java to automate the login/fetching开发者_如何学C the pin process?
What I want to achieve is, the user should enter his username and password in the app itself, and the app should automatically fetch the access pin. I don't want any web browser intervention. How can I achieve this? Please help!
hmm, i think it is not possible :( maybe with some ugly workarounds, like open a browser inside java.. something like that...
but without a browser, I think it's impossible.
Without diving into Twitter implementation gory details I can say that it uses so called form based authentication, i.e. browser sends user credentials to server as HTTP POST request. You should discover how is it working and do the same. You can use Firefox pluguin "live http headers" and/or wireshark to get information about the requests sent to the server.
Google has provided an authentication method called ClientLogin
you should see if twitter API provides a similar oauth method. this is the method appropriate for desktop apps. Search twitter API authentication methods for a similar method as Google ClientLogin. if there isn't one then try using an embedded swing browser like DJ Project and do the twitter auth inside the DJNative swing embedded browser.
I think I'd be trying the integrated browser approach. The http POST request seems complex to me and I've not done any web related coding before. The examples at DJ Project's site look promising. Thanks!
精彩评论