private void askOAuth() {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(Const.CONSUMER_KEY);
    configurationBuilder.setOAuthConsumerSecret(Const.CONSUMER_SECRET);
    Configuration configuration = configurationBuilder.build();
    twitter = new TwitterFactory(configuration).getInstance();

    try {
      requestToken = twitter.getOAuthRequestToken(Const.CALLBACK_URL);

      // Intent dialogIntent = new Intent(Intent.ACTION_VIEW,
      // Uri.parse(requestToken.getAuthenticationURL()));
      // oActivity.startActivity(dialogIntent);
      // oActivity.startActivityForResult(dialogIntent,0);
      Intent intent = ActivityHelper.createActivityIntent(oActivity, TwitterAuthActivity.class);
      intent.putExtra("auth_twitter_url", requestToken.getAuthenticationURL());
      // oActivity.startActivity(intent);
      oActivity.startActivityForResult(intent, 0);
      Log.v(
          this.getClass().getCanonicalName(),
          "askOAuth-> After:" + requestToken.getAuthenticationURL());
    } catch (TwitterException e) {
      e.printStackTrace();
    }
  }
  private void loginToTwitter() {
    boolean isLoggedIn = mSharedPreferences.getBoolean(PREF_KEY_TWITTER_LOGIN, false);

    if (!isLoggedIn) {
      final ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.setOAuthConsumerKey(consumerKey);
      builder.setOAuthConsumerSecret(consumerSecret);

      final Configuration configuration = builder.build();
      final TwitterFactory factory = new TwitterFactory(configuration);
      twitter = factory.getInstance();

      try {
        requestToken = twitter.getOAuthRequestToken(callbackUrl);

        /**
         * Loading twitter login page on webview for authorization Once authorized, results are
         * received at onActivityResult
         */
        final Intent intent = new Intent(this, WebViewActivity.class);
        intent.putExtra(WebViewActivity.EXTRA_URL, requestToken.getAuthenticationURL());
        startActivityForResult(intent, WEBVIEW_REQUEST_CODE);

      } catch (TwitterException e) {
        e.printStackTrace();
      }
    } else {
      Intent intent = new Intent(MainActivity.this, MenuActivity.class);
      startActivity(intent);
    }
  }
Esempio n. 3
0
  /** Function to login twitter */
  private void loginToTwitter() {
    // Check if already logged in
    if (!isTwitterLoggedInAlready()) {
      ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
      builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
      twitter4j.conf.Configuration configuration = builder.build();

      TwitterFactory factory = new TwitterFactory(configuration);
      twitter = factory.getInstance();

      Thread thread =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  try {

                    requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
                    Login_Activity.this.startActivity(
                        new Intent(
                            Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
              });
      thread.start();

    } else {
      // user already logged into twitter
      Toast.makeText(context, "already logged in 2222", Toast.LENGTH_SHORT).show();
    }
  }
Esempio n. 4
0
    /** getting Places JSON */
    protected String doInBackground(String... args) {
      Log.d("Tweet Text", "> " + args[0]);
      String status = args[0];
      try {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
        builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);

        // Access Token
        String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
        // Access Token Secret
        String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");

        AccessToken accessToken = new AccessToken(access_token, access_token_secret);
        Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

        // Update status
        twitter4j.Status response = twitter.updateStatus(status);

        Log.d("Status", "> " + response.getText());
      } catch (TwitterException e) {
        // Error in updating status
        Log.d("Twitter Update Error", e.getMessage());
      }
      return null;
    }
    protected Void doInBackground(String... args) {

      String status = args[0];
      try {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(consumerKey);
        builder.setOAuthConsumerSecret(consumerSecret);

        // Access Token
        String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
        // Access Token Secret
        String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");

        AccessToken accessToken = new AccessToken(access_token, access_token_secret);
        Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

        // Update status
        StatusUpdate statusUpdate = new StatusUpdate(status);
        twitter4j.Status response = twitter.updateStatus(statusUpdate);

        Log.d("Status", response.getText());

      } catch (TwitterException e) {
        Log.d("Failed to post!", e.getMessage());
      }
      return null;
    }
Esempio n. 6
0
  public void onConfigure(DashboardRepository repository) {
    for (Entry<Key, Map<String, ?>> settingsEntry :
        getSettings().getServiceSettings(TwitterService.class).entrySet()) {
      Key key = settingsEntry.getKey();

      TwitterSettings settings = new TwitterSettings(settingsEntry.getValue());

      String oAuthConsumerKey = settings.getApplicationKey().getKey();
      String oAuthConsumerSecret = settings.getApplicationKey().getSecret();

      List<Twitter> keyTwitters = new ArrayList<Twitter>();
      for (Entry<String, OAuthKey> tokenEntry : settings.getTokens().entrySet()) {

        OAuthKey token = tokenEntry.getValue();

        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(oAuthConsumerKey);
        builder.setOAuthConsumerSecret(oAuthConsumerSecret);
        builder.setOAuthAccessToken(token.getKey());
        builder.setOAuthAccessTokenSecret(token.getSecret());
        Configuration conf = builder.build();

        Authorization authorization = AuthorizationFactory.getInstance(conf);
        Twitter twitter = new TwitterFactory().getInstance(authorization);
        keyTwitters.add(twitter);
      }
      twitters.put(key, keyTwitters);
      mentions.put(key, new TreeSet<Status>());
      timeline.put(key, new TreeSet<Status>());
      repository.addDataSource(key, TwitterTimeline.class, new TwitterTimelineImpl(key, this));
      repository.addDataSource(key, TwitterMentions.class, new TwitterMentionsImpl(key, this));
    }
  }
Esempio n. 7
0
  public void inviteFriends(String id, String msg) {
    try {
      if (mTwitter == null) {
        ConfigurationBuilder confbuilder = new ConfigurationBuilder();
        Configuration conf =
            confbuilder
                .setOAuthConsumerKey(Const.CONSUMER_KEY)
                .setOAuthConsumerSecret(Const.CONSUMER_SECRET)
                .build();
        mTwitter = new TwitterFactory(conf).getInstance();
      }

      SharedPreferences pref = context.getSharedPreferences(Const.PREF_NAME, Context.MODE_PRIVATE);
      String accessToken = pref.getString(Const.PREF_KEY_ACCESS_TOKEN, null);
      String accessTokenSecret = pref.getString(Const.PREF_KEY_ACCESS_TOKEN_SECRET, null);
      if (accessToken == null || accessTokenSecret == null) {
        Toast.makeText(activity, "please Login first", Toast.LENGTH_SHORT).show();
        return;
      }
      mTwitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

      System.out.println("idddddd: " + id);
      mTwitter.sendDirectMessage(Long.parseLong(id), msg);

      Toast.makeText(activity, "Your Invitation has been sent!", Toast.LENGTH_SHORT).show();

    } catch (TwitterException e) {
      e.printStackTrace();
    } catch (NumberFormatException ne) {
      ne.printStackTrace();
    }
  }
Esempio n. 8
0
  public static void main(String[] args) throws Exception {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(CONSUMER_KEY);
    builder.setOAuthConsumerSecret(CONSUMER_SECRET);
    builder.setOAuthAccessToken(ACCESS_TOKEN);
    builder.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET);

    // 現行のTwitter4JではAPIのデフォルト呼び先がbetastream.twitter.comになっているので修正
    builder.setUserStreamBaseURL("https://userstream.twitter.com/2/");

    // Configurationを生成
    Configuration configuration = builder.build();

    /*        Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
                    .setOAuthConsumerSecret(CONSUMER_SECRET)
                    .setOAuthAccessToken(ACCESS_TOKEN)
                    .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET)
                    .build();
    */
    TwitterStream twStream = new TwitterStreamFactory(configuration).getInstance();
    // TwitterStream twStream = new TwitterStreamFactory().getInstance();
    twStream.addListener(new MyStatusListener());
    twStream.user();
    // twStream.sample();
  }
Esempio n. 9
0
  public String getCurrentUserScreenName() {

    try {
      if (mTwitter == null) {
        ConfigurationBuilder confbuilder = new ConfigurationBuilder();
        Configuration conf =
            confbuilder
                .setOAuthConsumerKey(Const.CONSUMER_KEY)
                .setOAuthConsumerSecret(Const.CONSUMER_SECRET)
                .build();
        mTwitter = new TwitterFactory(conf).getInstance();
      }
      SharedPreferences pref = context.getSharedPreferences(Const.PREF_NAME, Context.MODE_PRIVATE);
      String accessToken = pref.getString(Const.PREF_KEY_ACCESS_TOKEN, null);
      String accessTokenSecret = pref.getString(Const.PREF_KEY_ACCESS_TOKEN_SECRET, null);
      if (accessToken == null || accessTokenSecret == null) {
        Toast.makeText(activity, "please Login first", Toast.LENGTH_SHORT).show();
        return null;
      }

      mTwitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
      return mTwitter.getScreenName();

    } catch (TwitterException te) {
      te.printStackTrace();
    }
    return null;
  }
Esempio n. 10
0
 public TwitterUtil() {
   ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
   configurationBuilder.setOAuthConsumerKey(ConstantValues.TWITTER_CONSUMER_KEY);
   configurationBuilder.setOAuthConsumerSecret(ConstantValues.TWITTER_CONSUMER_SECRET);
   Configuration configuration = configurationBuilder.build();
   twitterFactory = new TwitterFactory(configuration);
   twitter = twitterFactory.getInstance();
 }
Esempio n. 11
0
 /**
  * Constructor to set the Twitter Access Details The details here are from a sample account i
  * created on twitter. if you have your account you can use that instead of this.
  */
 public TwitterClient() {
   cb = new ConfigurationBuilder();
   cb.setOAuthConsumerKey("X4X5rpyaRNvbwcVnV8j5i1izh");
   cb.setOAuthConsumerSecret("dosoSEWt0DeZbl0zO3Y61fiymszTvqrOZT9xzE8ikdI9imy1rl");
   cb.setOAuthAccessToken("2807566405-1jYRRu0Vs3tj3D56YM6ww4DqjByJqhLCl9Vpru9");
   cb.setOAuthAccessTokenSecret("svKkTebpr8jBmrmnfXiaygoYQndXJMPvo6CWIVniYrDb0");
   twitter = new TwitterFactory(cb.build()).getInstance();
 }
Esempio n. 12
0
  private void getTweetsFromTwitter() {
    try {
      ConfigurationBuilder confbuilder = new ConfigurationBuilder();
      confbuilder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
      confbuilder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);

      // Access Token
      String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
      // Access Token Secret
      String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");

      AccessToken accessToken = new AccessToken(access_token, access_token_secret);

      btnLogoutTwitter.setVisibility(View.GONE);
      btnGetTweets.setVisibility(View.GONE);
      lblUserName.setVisibility(View.GONE);
      btnShowOnMap.setVisibility(View.GONE);
      btnUsers.setVisibility(View.GONE);

      Twitter twitter = new TwitterFactory(confbuilder.build()).getInstance(accessToken);
      List<Status> statuses = twitter.getUserTimeline(USER_ID, new Paging(1, 10));

      IDs following = twitter.getFriendsIDs(USER_ID);

      long[] followingList = following.getIDs();

      for (int i = 0; i < followingList.length; i++) {

        Toast.makeText(getApplicationContext(), twitter.showUser(followingList[i]).toString(), 100)
            .show();
      }

      int count = 0;
      // Collections.reverse(statuses); // reverse order
      ArrayList<String> arrayList = new ArrayList<String>();
      for (Status status : statuses) {
        String tweettext =
            status.getUser().getName()
                + ":"
                + status.getText()
                + "\n ("
                + status.getCreatedAt().toLocaleString()
                + ")"
                + status.getGeoLocation();
        arrayList.add(tweettext);

        // now single tweet is in tweettext
      }

      ListView lv = (ListView) findViewById(R.id.storeTweet);
      ArrayAdapter<String> arrayAdapter =
          new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList);

      lv.setAdapter(arrayAdapter);
    } catch (Exception ex) {
      // failed to fetch tweet
    }
  }
Esempio n. 13
0
  /** Public API */
  public static void init(String consumerKey, String consumerSecret, String urlScheme) {
    if (mIsInitialized) return;

    mURLScheme = urlScheme;
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(consumerSecret);
    mConfiguration = builder.build();
    mIsInitialized = true;
  }
Esempio n. 14
0
 private static twitter4j.conf.Configuration getTwitterConfiguration(
     String strAccessToken, String token_secret) {
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.setUseSSL(true);
   builder.setOAuthConsumerKey(Constants.OFFICIAL_TWITTER_CONSUMER_KEY);
   builder.setOAuthConsumerSecret(Constants.OFFICIAL_TWITTER_CONSUMER_SECRET_KEY);
   if (token_secret != null && strAccessToken != null) {
     builder.setOAuthAccessToken(strAccessToken).setOAuthAccessTokenSecret(token_secret);
   }
   return builder.build();
 }
  /**
   * 承認情報の生成
   *
   * @param userModel
   * @param msg
   * @return
   */
  private ConfigurationBuilder getConfigurationBuilder(UserModel userModel) throws Exception {

    // 承認情報の生成
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(Constants.TWITTER_APP_API_KEY)
        .setOAuthConsumerSecret(Constants.TWITTER_APP_API_SECRET)
        .setOAuthAccessToken(userModel.getTwitterAccessToken())
        .setOAuthAccessTokenSecret(userModel.getTwitterTokenSecret());

    return cb;
  }
Esempio n. 16
0
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      ADOT4J4A adot4j4a = (ADOT4J4A) getActivity().getApplicationContext();

      ConfigurationBuilder confbuilder = new ConfigurationBuilder();
      confbuilder.setOAuthConsumerKey(ADOT4J4A.CONSUMER_KEY);
      confbuilder.setOAuthConsumerSecret(ADOT4J4A.CONSUMER_SECRET);
      confbuilder.setOAuthAccessToken(adot4j4a.getToken());
      confbuilder.setOAuthAccessTokenSecret(adot4j4a.getTokenSecret());
      mTwitter = new TwitterFactory(confbuilder.build()).getInstance();
    }
Esempio n. 17
0
  // construct Twitter instance using configuration
  static {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey(CONSUMER_KEY);
    cb.setOAuthConsumerSecret(CONSUMER_SECRET);
    cb.setOAuthAccessToken(ACCESS_TOKEN);
    cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET);

    Configuration conf = cb.build();

    twitter = new TwitterFactory(conf).getInstance();
    auth = new OAuth1(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
  }
Esempio n. 18
0
  public static final Twitter getTwitter(Context context) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(context.getString(R.string.twitter_consumer_key));
    builder.setOAuthConsumerSecret(context.getString(R.string.twitter_consumer_secret));
    builder.setOAuthAccessToken(pref.getString(PREF_TOKEN, null));
    builder.setOAuthAccessTokenSecret(pref.getString(PREF_TOKEN_SECRET, null));

    final Twitter twitter = new TwitterFactory(builder.build()).getInstance();

    return twitter;
  }
  /**
   * Posts a status to Twitter.
   *
   * @param statusText Text of the messsage.
   * @param at AccessToken to validate with
   * @throws Exception
   */
  public void updateStatus(String statusText, AccessToken at) throws Exception {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey(ourConsumerKey);
    cb.setOAuthConsumerSecret(ourConsumerSecret);
    cb.setOAuthAccessToken(at.getToken());
    cb.setOAuthAccessTokenSecret(at.getTokenSecret());

    myTwitter.setOAuthAccessToken(at);

    Status status = myTwitter.updateStatus(statusText);
    System.out.println("Successfully updated the status to [" + status.getText() + "].");
  }
Esempio n. 20
0
  @Override
  public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    statuses = new LinkedBlockingQueue<Status>(1000);
    this.spoutOutputCollector = collector;

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder
        .setOAuthConsumerKey(consumerKey)
        .setOAuthConsumerSecret(consumerSecret)
        .setOAuthAccessToken(accessToken)
        .setOAuthAccessTokenSecret(accessTokenSecret);

    OAuthAuthorization authAuthorization = new OAuthAuthorization(configurationBuilder.build());

    twitterStream = new TwitterStreamFactory().getInstance(authAuthorization);
    twitterStream.addListener(
        new StatusListener() {
          @Override
          public void onStatus(Status status) {
            statuses.offer(status);
          }

          @Override
          public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}

          @Override
          public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}

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

          @Override
          public void onStallWarning(StallWarning warning) {}

          @Override
          public void onException(Exception ex) {}
        });

    twitter = new TwitterFactory().getInstance(authAuthorization);
    filterQuery = new FilterQuery();

    if (filterQuery == null) {
      twitterStream.sample();
      ;
    } else {
      twitterStream.filter(filterQuery.track(filterWords));
      twitterStream.filter(filterQuery.language(filterLanguages));
    }
  }
Esempio n. 21
0
  public void twitt(final String msg) {

    if (mTwitter == null) {
      ConfigurationBuilder confbuilder = new ConfigurationBuilder();
      Configuration conf =
          confbuilder
              .setOAuthConsumerKey(Const.CONSUMER_KEY)
              .setOAuthConsumerSecret(Const.CONSUMER_SECRET)
              .build();
      mTwitter = new TwitterFactory(conf).getInstance();
    }

    SharedPreferences pref = context.getSharedPreferences(Const.PREF_NAME, Context.MODE_PRIVATE);
    String accessToken = pref.getString(Const.PREF_KEY_ACCESS_TOKEN, null);
    String accessTokenSecret = pref.getString(Const.PREF_KEY_ACCESS_TOKEN_SECRET, null);
    if (accessToken == null || accessTokenSecret == null) {
      Toast.makeText(activity, "please Login first", Toast.LENGTH_SHORT).show();
      return;
    }
    mTwitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                boolean success = true;
                try {
                  mTwitter.updateStatus(msg);

                } catch (TwitterException e) {
                  e.printStackTrace();
                  success = false;
                }

                final boolean finalSuccess = success;

                activity.runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (twitterListener != null) {
                          twitterListener.onTwittCompleted(finalSuccess);
                        }
                      }
                    });
              }
            })
        .start();
  }
 public static TwitterStream getTwitterStream() {
   AccessToken token = AccessTokenManager.getAccessToken();
   if (token == null) {
     return null;
   }
   ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
   twitter4j.conf.Configuration conf =
       configurationBuilder
           .setOAuthConsumerKey(getConsumerKey())
           .setOAuthConsumerSecret(getConsumerSecret())
           .setOAuthAccessToken(token.getToken())
           .setOAuthAccessTokenSecret(token.getTokenSecret())
           .build();
   return new TwitterStreamFactory(conf).getInstance();
 }
  public void askOAuth(Context context) {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(TwitterPrivateKeyAndSecret.CONSUMER_KEY);
    configurationBuilder.setOAuthConsumerSecret(TwitterPrivateKeyAndSecret.CONSUMER_SECRET);
    Configuration configuration = configurationBuilder.build();
    twitter = new TwitterFactory(configuration).getInstance();

    try {
      requestToken = twitter.getOAuthRequestToken(TwitterConsts.CALLBACK_URL);
      context.startActivity(
          new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
    } catch (TwitterException e) {
      e.printStackTrace();
    }
  }
Esempio n. 24
0
  public void LoginTwitter() {
    confbuilder = new ConfigurationBuilder();
    conf =
        confbuilder
            .setOAuthConsumerKey(Const.CONSUMER_KEY)
            .setOAuthConsumerSecret(Const.CONSUMER_SECRET)
            .build();
    mTwitter = new TwitterFactory(conf).getInstance();
    mTwitter.setOAuthAccessToken(null);

    new AsyncTask<Void, Void, RequestToken>() {
      protected void onPreExecute() {
        pDialog = new ProgressDialog(activity);
        pDialog.setMessage("Loading...");
        pDialog.show();
      };

      @Override
      protected RequestToken doInBackground(Void... params) {
        // TODO Auto-generated method stub
        try {
          mRequestToken = mTwitter.getOAuthRequestToken(Const.CALLBACK_URL);
        } catch (TwitterException e) {
          e.printStackTrace();
        }
        return mRequestToken;
      }

      protected void onPostExecute(RequestToken mRequestToken) {
        if (pDialog.isShowing()) {

          pDialog.dismiss();
          pDialog = null;
        }
        if (mRequestToken != null && mRequestToken.getAuthorizationURL() != null) {
          Intent intent = new Intent(activity, TwitterLogin.class);
          intent.putExtra(Const.IEXTRA_AUTH_URL, mRequestToken.getAuthorizationURL());
          activity.startActivityForResult(intent, 0);
        } else {
          Toast.makeText(
                  activity,
                  "not able to connect this time due to low internet conntection...",
                  Toast.LENGTH_SHORT)
              .show();
        }
      };
    }.execute();
  }
Esempio n. 25
0
  /** Function to login twitter */
  private void loginToTwitter() {
    // Check if already logged in
    if (!isTwitterLoggedInAlready()) {
      ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
      builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
      Configuration configuration = builder.build();

      TwitterFactory factory = new TwitterFactory(configuration);
      twitter = factory.getInstance();

      try {
        requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
        this.startActivity(
            new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));

        String status = txtUpdate.getText().toString();

        // Check for blank text
        if (status.trim().length() > 0) {
          // update status
          new updateTwitterStatus().execute(status);
        } else {
          // EditText is empty
          Toast.makeText(getApplicationContext(), "Please enter status message", Toast.LENGTH_SHORT)
              .show();
        }
      } catch (TwitterException e) {
        e.printStackTrace();
      }
    } else {
      // user already logged into twitter
      /*Toast.makeText(getApplicationContext(),
      "Already Logged into twitter", Toast.LENGTH_LONG).show();*/

      String status = txtUpdate.getText().toString();

      // Check for blank text
      if (status.trim().length() > 0) {
        // update status
        new updateTwitterStatus().execute(status);
      } else {
        // EditText is empty
        Toast.makeText(getApplicationContext(), "Please enter status message", Toast.LENGTH_SHORT)
            .show();
      }
    }
  }
  /** Posta in Twitt */
  public boolean postTwitt(String sMessage) {
    try {

      if (twitter != null) {
        try {
          AccessToken a =
              new AccessToken(
                  mSharedPreferences.getString(Const.PREF_KEY_TOKEN, ""),
                  mSharedPreferences.getString(Const.PREF_KEY_SECRET, ""));
          twitter.setOAuthAccessToken(a);
          Status oStatus = twitter.updateStatus(sMessage);
          Log.i(this.getClass().getCanonicalName(), "Post Twitter OK");
          return oStatus.isRetweet();
        } catch (IllegalArgumentException e) {
          Log.e(
              this.getClass().getCanonicalName(),
              "Post Twitter error: "
                  + mSharedPreferences.getString(Const.PREF_KEY_TOKEN, "")
                  + " "
                  + mSharedPreferences.getString(Const.PREF_KEY_SECRET, ""));
          return false;
        }
      } else {
        String oauthAccessToken = mSharedPreferences.getString(Const.PREF_KEY_TOKEN, "");
        String oAuthAccessTokenSecret = mSharedPreferences.getString(Const.PREF_KEY_SECRET, "");

        ConfigurationBuilder confbuilder = new ConfigurationBuilder();
        Configuration configuration =
            confbuilder
                .setOAuthConsumerKey(Const.CONSUMER_KEY)
                .setOAuthConsumerSecret(Const.CONSUMER_SECRET)
                .setOAuthAccessToken(oauthAccessToken)
                .setOAuthAccessTokenSecret(oAuthAccessTokenSecret)
                .build();
        twitter = new TwitterFactory(configuration).getInstance();

        Status oStatus = twitter.updateStatus(sMessage);
        Log.i(this.getClass().getCanonicalName(), "Post Twitter OK");
        return oStatus.isRetweet();
      }
    } catch (TwitterException e) {
      Log.e(this.getClass().getCanonicalName(), e.getMessage());
    } catch (NullPointerException e) {
      Log.e(this.getClass().getCanonicalName(), e.getMessage());
    }
    return false;
  }
Esempio n. 27
0
  private void loginWithTwitterWeb() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(Constants.TWITTER_CONSUMER_KEY);
    builder.setOAuthConsumerSecret(Constants.TWITTER_CONSUMER_SECRET);
    twitter4j.conf.Configuration configuration = builder.build();

    TwitterFactory factory = new TwitterFactory(configuration);
    twitter = factory.getInstance();

    CookieSyncManager.createInstance(mContext);
    CookieManager cookiemanager = CookieManager.getInstance();
    cookiemanager.removeSessionCookie();
    twitter.setOAuthAccessToken(null);

    mTwitterWebDialog = new WebDialog(mContext, twitter);
    mTwitterWebDialog.show();
  }
Esempio n. 28
0
  private void initTwitterClient() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(mConsumerKey);
    builder.setOAuthConsumerSecret(mConsumerSecret);

    String accessToken = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_TOKEN, null);
    String accessTokenSecret = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_SECRET, null);

    TwitterFactory factory = new TwitterFactory(builder.build());

    if (TextUtils.isEmpty(accessToken) && TextUtils.isEmpty(accessTokenSecret)) {
      mTwitter = factory.getInstance();
    } else {
      mTwitter =
          factory.getInstance(new twitter4j.auth.AccessToken(accessToken, accessTokenSecret));
    }
  }
  private void askOAuth() {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(Const.CONSUMER_KEY);
    configurationBuilder.setOAuthConsumerSecret(Const.CONSUMER_SECRET);
    Configuration configuration = configurationBuilder.build();
    twitter = new TwitterFactory(configuration).getInstance();

    try {
      requestToken = twitter.getOAuthRequestToken(Const.CALLBACK_URL);
      // System.out.println(requestToken.toString());
      Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show();
      this.startActivity(
          new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
    } catch (TwitterException e) {
      e.printStackTrace();
    }
  }
Esempio n. 30
0
  public static TwitterModule newInstance(Context context, TwitterListener listener) {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    Configuration configuration =
        configurationBuilder
            .setOAuthConsumerKey(BuildConfig.TWITTER_CONSUMER_KEY)
            .setOAuthConsumerSecret(BuildConfig.TWITTER_CONSUMER_SECRET)
            .setOAuthAccessToken(BuildConfig.TWITTER_ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(BuildConfig.TWITTER_ACCESS_TOKEN_SECRET)
            .build();
    TwitterStream twitterStream = new TwitterStreamFactory(configuration).getInstance();

    String preferencesKey = context.getString(R.string.preference_key_tweet_filter);
    String query =
        PreferenceManager.getDefaultSharedPreferences(context)
            .getString(preferencesKey, DEFAULT_QUERY);
    return new TwitterModule(twitterStream, query, listener);
  }