Ejemplo n.º 1
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()));
   }
 }
Ejemplo n.º 2
0
 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()));
     }
 }
Ejemplo n.º 3
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;
  }
Ejemplo n.º 4
0
  private void startAuth() {
    final Uri callbackUrl = getCallbackUrl();
    final Twitter twitter = getTwitter(this);
    Configuration conf = twitter.getConfiguration();
    if (conf.getOAuthAccessToken() != null && conf.getOAuthAccessTokenSecret() != null) {
      Toast.makeText(getApplicationContext(), "認証済みです。", Toast.LENGTH_LONG).show();
      return;
    }

    setProgressBarIndeterminateVisibility(true);

    // 通信開始
    new AsyncTask<Void, Void, RequestToken>() {
      @Override
      protected RequestToken doInBackground(Void... params) {
        RequestToken requestToken = null;
        try {
          requestToken = twitter.getOAuthRequestToken(callbackUrl.toString());
        } catch (TwitterException e) {
          Log.e(TAG, "認証失敗", e);
        }
        return requestToken;
      }

      @Override
      protected void onPostExecute(RequestToken requestToken) {
        super.onPostExecute(requestToken);

        setProgressBarIndeterminateVisibility(false);

        mRequestToken = requestToken;
        if (requestToken != null) {
          String authorizationUrl = requestToken.getAuthorizationURL();
          Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authorizationUrl));
          startActivity(intent);
        } else {
          Toast.makeText(getApplicationContext(), "Request Tokenが取得できませんでした。", Toast.LENGTH_LONG)
              .show();
        }
      }
    }.execute();
  }