Exemplo n.º 1
0
  /**
   * @param conf configuration
   * @param supportsOAuth set true if the authorization instance required to be OAuth'ed
   * @return authorization instance
   * @deprecated use {@link #getInstance(twitter4j.conf.Configuration)} instead
   */
  public static Authorization getInstance(Configuration conf, boolean supportsOAuth) {
    Authorization auth = null;
    String consumerKey = conf.getOAuthConsumerKey();
    String consumerSecret = conf.getOAuthConsumerSecret();

    if (supportsOAuth && null != consumerKey && null != consumerSecret) {
      OAuthAuthorization oauth;
      oauth = new OAuthAuthorization(conf, consumerKey, consumerSecret);
      String accessToken = conf.getOAuthAccessToken();
      String accessTokenSecret = conf.getOAuthAccessTokenSecret();
      if (null != accessToken && null != accessTokenSecret) {
        oauth.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
      }
      auth = oauth;
    } else {
      String screenName = conf.getUser();
      String password = conf.getPassword();
      if (null != screenName && null != password) {
        auth = new BasicAuthorization(screenName, password);
      }
    }
    if (null == auth) {
      auth = NullAuthorization.getInstance();
    }
    return auth;
  }
Exemplo n.º 2
0
 /** @param conf configuration */
 public OAuthAuthorization(final Configuration conf) {
   this.conf = conf;
   http = new HttpClientWrapper(conf);
   setOAuthConsumer(conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret());
   if (conf.getOAuthAccessToken() != null && conf.getOAuthAccessTokenSecret() != null) {
     setOAuthAccessToken(
         new AccessToken(conf.getOAuthAccessToken(), conf.getOAuthAccessTokenSecret()));
   }
 }
Exemplo n.º 3
0
 /**
  * Returns a OAuth Authenticated instance.<br>
  * consumer key and consumer Secret must be provided by twitter4j.properties, or system
  * properties.<br>
  * Unlike {@link Twitter#setOAuthAccessToken(twitter4j.auth.AccessToken)}, this factory method
  * potentially returns a cached instance.
  *
  * @param accessToken access token
  * @return an instance
  * @since Twitter4J 2.1.9
  */
 public Twitter getInstance(AccessToken accessToken) {
   String consumerKey = conf.getOAuthConsumerKey();
   String consumerSecret = conf.getOAuthConsumerSecret();
   if (null == consumerKey && null == consumerSecret) {
     throw new IllegalStateException("Consumer key and Consumer secret not supplied.");
   }
   OAuthAuthorization oauth = new OAuthAuthorization(conf);
   oauth.setOAuthAccessToken(accessToken);
   return getInstance(oauth);
 }
 public OAuthAuthorization(Configuration configuration)
 {
     consumerKey = "";
     realm = null;
     oauthToken = null;
     conf = configuration;
     http = new HttpClientWrapper(configuration);
     setOAuthConsumer(configuration.getOAuthConsumerKey(), configuration.getOAuthConsumerSecret());
     if (configuration.getOAuthAccessToken() != null && configuration.getOAuthAccessTokenSecret() != null)
     {
         setOAuthAccessToken(new AccessToken(configuration.getOAuthAccessToken(), configuration.getOAuthAccessTokenSecret()));
     }
 }
Exemplo n.º 5
0
 // constructors
 public OAuthAuthorization(Configuration conf) {
   this(conf, conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret());
 }