Example usage for twitter4j.auth OAuthAuthorization getOAuthAccessToken

List of usage examples for twitter4j.auth OAuthAuthorization getOAuthAccessToken

Introduction

In this page you can find the example usage for twitter4j.auth OAuthAuthorization getOAuthAccessToken.

Prototype

@Override
    public AccessToken getOAuthAccessToken(RequestToken requestToken) throws TwitterException 

Source Link

Usage

From source file:inujini_.hatate.service.OauthService.java

License:MIT License

/**
 * AccessToken?./*  w ww.  ja va 2s  . c  o m*/
 * @param intent
 * @throws IllegalStateException OAuth????????intent????????????.
 */
private void getAccessToken(Intent intent) {
    // validate
    if (intent.getData() == null) {
        IllegalStateException e = new IllegalStateException(
                "OAuth is success but intent's data (URI) is null.");

        CallbackBroadcastReceiver.Data data = CallbackBroadcastReceiver.Data.create(e);
        sendBroadcast(CallbackBroadcastReceiver.createIntent(data));
        return;
    }

    OAuthAuthorization oauth = null;

    // OAuthAuthorization
    try {
        oauth = deserialize("oauth.dat");
    } catch (Exception e) {
        e.printStackTrace();
        CallbackBroadcastReceiver.Data data = CallbackBroadcastReceiver.Data.create(e);
        sendBroadcast(CallbackBroadcastReceiver.createIntent(data));
        return;
    }

    // AccessToken
    String verifier = intent.getData().getQueryParameter("oauth_verifier");
    AccessToken accessToken;
    try {
        accessToken = oauth.getOAuthAccessToken(verifier);
    } catch (TwitterException e) {
        e.printStackTrace();
        CallbackBroadcastReceiver.Data data = CallbackBroadcastReceiver.Data.create(e);
        sendBroadcast(CallbackBroadcastReceiver.createIntent(data));
        return;
    }

    CallbackBroadcastReceiver.Data data = CallbackBroadcastReceiver.Data.create(accessToken);
    sendBroadcast(CallbackBroadcastReceiver.createIntent(data));
}