Example usage for twitter4j.conf ConfigurationBuilder setIncludeEntitiesEnabled

List of usage examples for twitter4j.conf ConfigurationBuilder setIncludeEntitiesEnabled

Introduction

In this page you can find the example usage for twitter4j.conf ConfigurationBuilder setIncludeEntitiesEnabled.

Prototype

public ConfigurationBuilder setIncludeEntitiesEnabled(boolean enabled) 

Source Link

Usage

From source file:benche.me.TwitterParser.Main.java

License:Open Source License

    /**
   * Configure twitter API connection for tweet streaming
   * @return TwitterStream instance//from  ww  w .ja  v a  2 s . co m
   */
  private static TwitterStream configureStream() {
       ConfigurationBuilder cb = new ConfigurationBuilder();
       cb.setOAuthConsumerKey(Constants.CONSUMER_KEY_KEY);
       cb.setOAuthConsumerSecret(Constants.CONSUMER_SECRET_KEY);
       cb.setOAuthAccessToken(Constants.ACCESS_TOKEN_KEY);
       cb.setOAuthAccessTokenSecret(Constants.ACCESS_TOKEN_SECRET_KEY);
       cb.setJSONStoreEnabled(true);
       cb.setIncludeEntitiesEnabled(true);
       return new TwitterStreamFactory(cb.build()).getInstance();
}

From source file:com.cloudera.flume.source.TwitterSource.java

License:Apache License

/**
 * The initialization method for the Source. The context contains all the
 * Flume configuration info, and can be used to retrieve any configuration
 * values necessary to set up the Source.
 *//* w  w  w.  ja  v a2  s.c  o  m*/
@Override
public void configure(Context context) {
    consumerKey = context.getString(TwitterSourceConstants.CONSUMER_KEY_KEY);
    consumerSecret = context.getString(TwitterSourceConstants.CONSUMER_SECRET_KEY);
    accessToken = context.getString(TwitterSourceConstants.ACCESS_TOKEN_KEY);
    accessTokenSecret = context.getString(TwitterSourceConstants.ACCESS_TOKEN_SECRET_KEY);

    String keywordString = context.getString(TwitterSourceConstants.KEYWORDS_KEY, "");
    keywords = keywordString.split(",");
    for (int i = 0; i < keywords.length; i++) {
        keywords[i] = keywords[i].trim();
    }

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);
    cb.setIncludeEntitiesEnabled(true);

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
}

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static Twitter getTwitterInstance(final Context context, final long account_id,
        final boolean include_entities, final boolean include_rts, final boolean use_httpclient) {
    if (context == null)
        return null;
    final SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME,
            Context.MODE_PRIVATE);
    final boolean enable_gzip_compressing = preferences != null
            ? preferences.getBoolean(PREFERENCE_KEY_GZIP_COMPRESSING, true)
            : true;// w  w w .j  av  a2  s  . c  o m
    final boolean ignore_ssl_error = preferences != null
            ? preferences.getBoolean(PREFERENCE_KEY_IGNORE_SSL_ERROR, false)
            : false;
    final boolean enable_proxy = preferences != null
            ? preferences.getBoolean(PREFERENCE_KEY_ENABLE_PROXY, false)
            : false;
    final String consumer_key = preferences != null
            ? preferences.getString(PREFERENCE_KEY_CONSUMER_KEY, CONSUMER_KEY)
            : CONSUMER_KEY;
    final String consumer_secret = preferences != null
            ? preferences.getString(PREFERENCE_KEY_CONSUMER_SECRET, CONSUMER_SECRET)
            : CONSUMER_SECRET;

    Twitter twitter = null;
    final StringBuilder where = new StringBuilder();
    where.append(Accounts.USER_ID + "=" + account_id);
    final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, Accounts.COLUMNS,
            where.toString(), null, null);
    if (cur != null) {
        if (cur.getCount() == 1) {
            cur.moveToFirst();
            final ConfigurationBuilder cb = new ConfigurationBuilder();
            setUserAgent(context, cb);
            if (use_httpclient) {
                cb.setHttpClientImplementation(HttpClientImpl.class);
            }
            cb.setGZIPEnabled(enable_gzip_compressing);
            if (enable_proxy) {
                final String proxy_host = preferences.getString(PREFERENCE_KEY_PROXY_HOST, null);
                final int proxy_port = parseInt(preferences.getString(PREFERENCE_KEY_PROXY_PORT, "-1"));
                if (!isNullOrEmpty(proxy_host) && proxy_port > 0) {
                    cb.setHttpProxyHost(proxy_host);
                    cb.setHttpProxyPort(proxy_port);
                }

            }
            final String rest_base_url = cur.getString(cur.getColumnIndexOrThrow(Accounts.REST_BASE_URL));
            final String signing_rest_base_url = cur
                    .getString(cur.getColumnIndexOrThrow(Accounts.SIGNING_REST_BASE_URL));
            final String search_base_url = cur.getString(cur.getColumnIndexOrThrow(Accounts.SEARCH_BASE_URL));
            final String upload_base_url = cur.getString(cur.getColumnIndexOrThrow(Accounts.UPLOAD_BASE_URL));
            final String oauth_base_url = cur.getString(cur.getColumnIndexOrThrow(Accounts.OAUTH_BASE_URL));
            final String signing_oauth_base_url = cur
                    .getString(cur.getColumnIndexOrThrow(Accounts.SIGNING_OAUTH_BASE_URL));
            //if (!isNullOrEmpty(rest_base_url)) {
            cb.setRestBaseURL(DEFAULT_REST_BASE_URL);
            //}
            //if (!isNullOrEmpty(search_base_url)) {
            cb.setSearchBaseURL(DEFAULT_SEARCH_BASE_URL);
            //}
            cb.setIncludeEntitiesEnabled(include_entities);
            cb.setIncludeRTsEnabled(include_rts);

            switch (cur.getInt(cur.getColumnIndexOrThrow(Accounts.AUTH_TYPE))) {
            case Accounts.AUTH_TYPE_OAUTH:
            case Accounts.AUTH_TYPE_XAUTH:
                if (isNullOrEmpty(consumer_key) || isNullOrEmpty(consumer_secret)) {
                    cb.setOAuthConsumerKey(CONSUMER_KEY);
                    cb.setOAuthConsumerSecret(CONSUMER_SECRET);
                } else {
                    cb.setOAuthConsumerKey(consumer_key);
                    cb.setOAuthConsumerSecret(consumer_secret);
                }
                twitter = new TwitterFactory(cb.build()).getInstance(
                        new AccessToken(cur.getString(cur.getColumnIndexOrThrow(Accounts.OAUTH_TOKEN)),
                                cur.getString(cur.getColumnIndexOrThrow(Accounts.TOKEN_SECRET))));
                break;
            case Accounts.AUTH_TYPE_BASIC:
                twitter = new TwitterFactory(cb.build()).getInstance(
                        new BasicAuthorization(cur.getString(cur.getColumnIndexOrThrow(Accounts.USERNAME)),
                                cur.getString(cur.getColumnIndexOrThrow(Accounts.BASIC_AUTH_PASSWORD))));
                break;
            default:
            }
        }
        cur.close();
    }
    return twitter;
}

From source file:com.hortonworks.amuise.cdrstorm.kafka.producers.CDRTestDataProducer.java

private void start() {

    /**//from  w  w w . j a  v  a2 s .  co m
     * Kafka Twitter Producer properties *
     */
    Properties twitterconprops = new Properties();
    twitterconprops.put("metadata.broker.list", globalconfigs.getProperty("twitter4j.brokerlist"));
    twitterconprops.put("serializer.class", globalconfigs.getProperty("twitter4j.serializer"));
    twitterconprops.put("request.required.acks", globalconfigs.getProperty("twitter4j.requiredacks"));
    ProducerConfig twitterproducerconfig = new ProducerConfig(twitterconprops);
    final Producer<String, String> twitterproducer = new Producer<String, String>(twitterproducerconfig);

    /**
     * Kafka CDR Producer properties *
     */
    Properties cdrconprops = new Properties();
    cdrconprops.put("metadata.broker.list", globalconfigs.getProperty("cdr.brokerlist"));
    cdrconprops.put("serializer.class", globalconfigs.getProperty("cdr.serializer"));
    cdrconprops.put("request.required.acks", globalconfigs.getProperty("cdr.requiredacks"));
    ProducerConfig cdrproducerconfig = new ProducerConfig(cdrconprops);
    final Producer<String, String> cdrproducer = new Producer<String, String>(cdrproducerconfig);

    /**
     * Twitter4j properties *
     */
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(globalconfigs.getProperty("twitter4j.consumerkey"));
    cb.setOAuthConsumerSecret(globalconfigs.getProperty("twitter4j.consumersecretkey"));
    cb.setOAuthAccessToken(globalconfigs.getProperty("twitter4j.accesstokenkey"));
    cb.setOAuthAccessTokenSecret(globalconfigs.getProperty("twitter4j.accesstokensecretkey"));
    cb.setJSONStoreEnabled(true);
    cb.setIncludeEntitiesEnabled(true);

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

    /**
     * Twitter listener *
     */
    StatusListener listener = new StatusListener() {
        // The onStatus method is executed every time a new tweet comes
        // in.
        public void onStatus(Status status) {

            StringBuilder sb = new StringBuilder();
            sb.append(status.getUser().getScreenName());
            sb.append("|");
            sb.append(status.getCreatedAt());
            sb.append("|");
            sb.append(status.getRetweetCount());
            sb.append("|");
            sb.append(status.getSource());
            sb.append("|");
            sb.append(status.getText());

            //call CDR create message
            String cdrmessage = createCDRMessage(status.getText());

            //Debug output
            System.out.println("_________________________________________________________");
            System.out.println(sb.toString());
            System.out.println("cdr message: " + cdrmessage);
            System.out.println("_________________________________________________________");

            //call producer for tweet
            KeyedMessage<String, String> twitterdata = new KeyedMessage<String, String>(
                    globalconfigs.getProperty("twitter4j.kafkatopic"), sb.toString());
            twitterproducer.send(twitterdata);

            //call producer for cdr
            KeyedMessage<String, String> cdrmessagedata = new KeyedMessage<String, String>(
                    globalconfigs.getProperty("cdr.kafkatopic"), cdrmessage);
            cdrproducer.send(cdrmessagedata);

        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        public void onScrubGeo(long userId, long upToStatusId) {
        }

        public void onException(Exception ex) {
            System.out.println("General Exception: shutting down Twitter sample stream...");
            System.out.println(ex.getMessage());
            ex.printStackTrace();
            twitterStream.shutdown();
        }

        public void onStallWarning(StallWarning warning) {
        }
    };

    twitterStream.addListener(listener);

    // Filter stream with targeted words
    String filterstring = globalconfigs.getProperty("twitter4j.filterwords");
    FilterQuery filterq = new FilterQuery();
    filterq.track(filterstring.split(","));
    twitterStream.filter(filterq);

    //twitterStream.sample();
}

From source file:com.pulzitinc.flume.source.TwitterSource.java

License:Apache License

/**
 * The initialization method for the Source. The context contains all the
 * Flume configuration info, and can be used to retrieve any configuration
 * values necessary to set up the Source.
 *///from ww w . j a  v a2 s.co m
@Override
public void configure(Context context) {

    logger.info(context.toString());

    consumerKey = context.getString(TwitterSourceConstants.CONSUMER_KEY_KEY);
    consumerSecret = context.getString(TwitterSourceConstants.CONSUMER_SECRET_KEY);
    accessToken = context.getString(TwitterSourceConstants.ACCESS_TOKEN_KEY);
    accessTokenSecret = context.getString(TwitterSourceConstants.ACCESS_TOKEN_SECRET_KEY);

    String accountIdsString = context.getString(TwitterSourceConstants.ACCOUNT_IDS_KEY, "");
    if (accountIdsString.trim().length() == 0) {
        throw new IllegalStateException("No accounts to follow provided");
    } else {
        String[] accountIds = accountIdsString.split(",");
        accountsToFollow = new long[accountIds.length];
        for (int i = 0; i < accountIds.length; i++) {
            accountsToFollow[i] = Long.valueOf(accountIds[i]);
        }
    }

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);
    cb.setIncludeEntitiesEnabled(true);

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
}

From source file:com.sinfonier.drains.TweetIt.java

License:Apache License

@Override
public void userexecute() {

    ConfigurationBuilder config = new ConfigurationBuilder();
    config.setOAuthConsumerKey(this.CONSUMER_KEY);
    config.setOAuthConsumerSecret(this.CONSUMER_SECRET);
    config.setOAuthAccessToken(this.ACCESS_TOKEN);
    config.setOAuthAccessTokenSecret(this.ACCESS_TOKEN_SECRET);
    config.setJSONStoreEnabled(true);// ww  w . j a v a 2 s.co  m
    config.setIncludeEntitiesEnabled(true);
    try {
        TwitterFactory tf = new TwitterFactory(config.build());
        Twitter twitter = tf.getInstance();
        Status status = twitter.updateStatus(this.customText + " " + this.getField(this.fieldToTweet));
        System.out.println("Successfully updated the status to [" + status.getText() + "].");
    } catch (TwitterException te) {
        te.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.sinfonier.spouts.Twitter.java

License:Apache License

/**
 * Create a TwitterStream. Requires Twitter API keys.
 * /*www.j a v  a  2s . c  o  m*/
 * @return {@link twitter4j.TwitterStream}
 */
private TwitterStream createTwitterStream() {

    ConfigurationBuilder config = new ConfigurationBuilder();
    config.setOAuthConsumerKey(xml.get(CONSUMER_KEY, true));
    config.setOAuthConsumerSecret(xml.get(CONSUMER_SECRET, true));
    config.setOAuthAccessToken(xml.get(ACCESS_TOKEN, true));
    config.setOAuthAccessTokenSecret(xml.get(ACCESS_TOKEN_SECRET, true));
    config.setJSONStoreEnabled(true);
    config.setIncludeEntitiesEnabled(true);

    return new TwitterStreamFactory(config.build()).getInstance();
}

From source file:com.unisa.flume.source.TwitterSource.java

License:Apache License

/**
 * The initialization method for the Source. The context contains all the
 * Flume configuration info, and can be used to retrieve any configuration
 * values necessary to set up the Source.
 *///from  www.j  a  v  a 2 s .c o m
@Override
public void configure(Context context) {
    consumerKey = context.getString(TwitterSourceConstants.CONSUMER_KEY_KEY);
    consumerSecret = context.getString(TwitterSourceConstants.CONSUMER_SECRET_KEY);
    accessToken = context.getString(TwitterSourceConstants.ACCESS_TOKEN_KEY);
    accessTokenSecret = context.getString(TwitterSourceConstants.ACCESS_TOKEN_SECRET_KEY);

    String keywordString = context.getString(TwitterSourceConstants.KEYWORDS_KEY, "");
    if (keywordString.trim().length() == 0) {
        keywords = new String[0];
    } else {
        keywords = keywordString.split(",");
        for (int i = 0; i < keywords.length; i++) {
            keywords[i] = keywords[i].trim();
        }
    }

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);
    cb.setIncludeEntitiesEnabled(true);

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
}

From source file:de.fhm.bigdata.projekt.dataimport.TwitterSource.java

License:Apache License

/**
 * The initialization method for the Source. The context contains all the
 * Flume configuration info, and can be used to retrieve any configuration
 * values necessary to set up the Source.
 *//*from   w w w  .j a  va  2 s  .c om*/
@Override
public void configure(Context context) {
    consumerKey = context.getString(TwitterSourceConstants.CONSUMER_KEY_KEY);
    consumerSecret = context.getString(TwitterSourceConstants.CONSUMER_SECRET_KEY);
    accessToken = context.getString(TwitterSourceConstants.ACCESS_TOKEN_KEY);
    accessTokenSecret = context.getString(TwitterSourceConstants.ACCESS_TOKEN_SECRET_KEY);

    proxyEnabled = context.getBoolean(TwitterSourceConstants.PROXY_ENABLED);
    proxyHost = context.getString(TwitterSourceConstants.PROXY_HOST);
    proxyPort = context.getInteger(TwitterSourceConstants.PROXY_PORT);

    String keywordString = context.getString(TwitterSourceConstants.KEYWORDS_KEY, "");
    if (keywordString.trim().length() == 0) {
        keywords = new String[0];
    } else {
        keywords = keywordString.split(",");
        for (int i = 0; i < keywords.length; i++) {
            keywords[i] = keywords[i].trim();
        }
    }

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);
    cb.setIncludeEntitiesEnabled(true);

    if (proxyEnabled) {
        cb.setHttpProxyHost(proxyHost);
        cb.setHttpProxyPort(proxyPort);//port
    }

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
}

From source file:de.vanita5.twittnuker.util.Utils.java

License:Open Source License

public static Twitter getTwitterInstance(final Context context, final long accountId,
        final boolean includeEntities, final boolean includeRetweets, final boolean apacheHttp,
        final String mediaProvider, final String mediaProviderAPIKey) {
    if (context == null)
        return null;
    final TwittnukerApplication app = TwittnukerApplication.getInstance(context);
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final int connection_timeout = prefs.getInt(KEY_CONNECTION_TIMEOUT, 10) * 1000;
    final boolean enableGzip = prefs.getBoolean(KEY_GZIP_COMPRESSING, true);
    final boolean ignoreSSLError = prefs.getBoolean(KEY_IGNORE_SSL_ERROR, false);
    final boolean enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false);
    // Here I use old consumer key/secret because it's default key for older
    // versions//from  w  w  w  .ja  va  2  s  .  com
    final String where = Where.equals(new Column(Accounts.ACCOUNT_ID), accountId).getSQL();
    final Cursor c = ContentResolverUtils.query(context.getContentResolver(), Accounts.CONTENT_URI,
            Accounts.COLUMNS, where, null, null);
    if (c == null)
        return null;
    try {
        if (!c.moveToFirst())
            return null;
        final ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setHostAddressResolverFactory(new TwidereHostResolverFactory(app));
        if (apacheHttp) {
            cb.setHttpClientFactory(new TwidereHttpClientFactory(app));
        }
        cb.setHttpConnectionTimeout(connection_timeout);
        cb.setGZIPEnabled(enableGzip);
        cb.setIgnoreSSLError(ignoreSSLError);
        if (enableProxy) {
            final String proxy_host = prefs.getString(KEY_PROXY_HOST, null);
            final int proxy_port = ParseUtils.parseInt(prefs.getString(KEY_PROXY_PORT, "-1"));
            if (!isEmpty(proxy_host) && proxy_port > 0) {
                cb.setHttpProxyHost(proxy_host);
                cb.setHttpProxyPort(proxy_port);
            }
        }
        final String prefConsumerKey = prefs.getString(KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY_2);
        final String prefConsumerSecret = prefs.getString(KEY_CONSUMER_SECRET, TWITTER_CONSUMER_SECRET_2);
        final String apiUrlFormat = c.getString(c.getColumnIndex(Accounts.API_URL_FORMAT));
        final String consumerKey = trim(c.getString(c.getColumnIndex(Accounts.CONSUMER_KEY)));
        final String consumerSecret = trim(c.getString(c.getColumnIndex(Accounts.CONSUMER_SECRET)));
        final boolean sameOAuthSigningUrl = c.getInt(c.getColumnIndex(Accounts.SAME_OAUTH_SIGNING_URL)) == 1;
        final boolean noVersionSuffix = c.getInt(c.getColumnIndex(Accounts.NO_VERSION_SUFFIX)) == 1;
        if (!isEmpty(apiUrlFormat)) {
            final String versionSuffix = noVersionSuffix ? null : "/1.1/";
            cb.setRestBaseURL(getApiUrl(apiUrlFormat, "api", versionSuffix));
            cb.setOAuthBaseURL(getApiUrl(apiUrlFormat, "api", "/oauth/"));
            cb.setUploadBaseURL(getApiUrl(apiUrlFormat, "upload", versionSuffix));
            if (!sameOAuthSigningUrl) {
                cb.setSigningRestBaseURL(DEFAULT_SIGNING_REST_BASE_URL);
                cb.setSigningOAuthBaseURL(DEFAULT_SIGNING_OAUTH_BASE_URL);
                cb.setSigningUploadBaseURL(DEFAULT_SIGNING_UPLOAD_BASE_URL);
            }
        }
        if (isOfficialConsumerKeySecret(context, consumerKey, consumerSecret)) {
            setMockOfficialUserAgent(context, cb);
        } else {
            setUserAgent(context, cb);
        }

        if (!isEmpty(mediaProvider)) {
            cb.setMediaProvider(mediaProvider);
        }
        if (!isEmpty(mediaProviderAPIKey)) {
            cb.setMediaProviderAPIKey(mediaProviderAPIKey);
        }
        cb.setIncludeEntitiesEnabled(includeEntities);
        cb.setIncludeRTsEnabled(includeRetweets);
        cb.setIncludeReplyCountEnabled(true);
        cb.setIncludeDescendentReplyCountEnabled(true);
        switch (c.getInt(c.getColumnIndexOrThrow(Accounts.AUTH_TYPE))) {
        case Accounts.AUTH_TYPE_OAUTH:
        case Accounts.AUTH_TYPE_XAUTH: {
            if (!isEmpty(consumerKey) && !isEmpty(consumerSecret)) {
                cb.setOAuthConsumerKey(consumerKey);
                cb.setOAuthConsumerSecret(consumerSecret);
            } else if (!isEmpty(prefConsumerKey) && !isEmpty(prefConsumerSecret)) {
                cb.setOAuthConsumerKey(prefConsumerKey);
                cb.setOAuthConsumerSecret(prefConsumerSecret);
            } else {
                cb.setOAuthConsumerKey(TWITTER_CONSUMER_KEY_2);
                cb.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET_2);
            }
            final String token = c.getString(c.getColumnIndexOrThrow(Accounts.OAUTH_TOKEN));
            final String tokenSecret = c.getString(c.getColumnIndexOrThrow(Accounts.OAUTH_TOKEN_SECRET));
            if (isEmpty(token) || isEmpty(tokenSecret))
                return null;
            cb.setOAuthAccessToken(token);
            cb.setOAuthAccessTokenSecret(tokenSecret);
            return new TwitterFactory(cb.build()).getInstance(new AccessToken(token, tokenSecret));
        }
        case Accounts.AUTH_TYPE_BASIC: {
            final String screenName = c.getString(c.getColumnIndexOrThrow(Accounts.SCREEN_NAME));
            final String username = c.getString(c.getColumnIndexOrThrow(Accounts.BASIC_AUTH_USERNAME));
            final String loginName = username != null ? username : screenName;
            final String password = c.getString(c.getColumnIndexOrThrow(Accounts.BASIC_AUTH_PASSWORD));
            if (isEmpty(loginName) || isEmpty(password))
                return null;
            return new TwitterFactory(cb.build()).getInstance(new BasicAuthorization(loginName, password));
        }
        case Accounts.AUTH_TYPE_TWIP_O_MODE: {
            return new TwitterFactory(cb.build()).getInstance(new TwipOModeAuthorization());
        }
        default: {
            return null;
        }
        }
    } finally {
        c.close();
    }
}