public BasicAuthorization(String userId, String password) { this.userId = userId; this.password = password; this.basic = encodeBasicAuthenticationString(); }
@Override public String getAuthorizationHeader(HttpRequest req) { return basic.getAuthorizationHeader(req); }
public String getPassword() { return basic.getPassword(); }
Configuration configuration = new ConfigurationBuilder() .setOAuthConsumerKey("your_customer_key") .setOAuthConsumerSecret("your_customer_secret") .build(); Twitter twitter = new TwitterFactory(configuration).getInstance(new BasicAuthorization("username", "password")); AccessToken token = twitter.getOAuthAccessToken();
this.auth = auth; OAuthAuthorization oauthAuth = (OAuthAuthorization) auth; oauthAccessToken = oauthAuth.getOAuthAccessToken(basicAuth.getUserId(), basicAuth.getPassword()); } else { throw new IllegalStateException("consumer key / secret combination not supplied.");
public String getUserId() { return basic.getUserId(); }
@Override public boolean isEnabled() { return basic.isEnabled(); } }
String password = conf.getPassword(); if (screenName != null && password != null) { auth = new BasicAuthorization(screenName, password);
@Override public String getScreenName() throws TwitterException, IllegalStateException { if (!auth.isEnabled()) { throw new IllegalStateException( "Neither user ID/password combination nor OAuth consumer key/secret combination supplied"); } if (null == screenName) { if (auth instanceof BasicAuthorization) { screenName = ((BasicAuthorization) auth).getUserId(); if (screenName.contains("@")) { screenName = null; } } if (null == screenName) { // retrieve the screen name if this instance is authenticated with OAuth or email address fillInIDAndScreenName(); } } return screenName; }