コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig));
    TwitterSession session = Twitter.getInstance().core.getSessionManager().getActiveSession();

    if (session != null) {
      Twitter4JFactory.generateInstance(
          TWITTER_KEY, TWITTER_SECRET, session.getAuthToken().token, session.getAuthToken().secret);
      Twitter.getApiClient(session)
          .getAccountService()
          .verifyCredentials(
              false,
              true,
              new com.twitter.sdk.android.core.Callback<User>() {

                Intent intent = new Intent(LoginActivity.this, MainActivity.class);

                @Override
                public void success(Result<User> result) {
                  startActivity(intent);
                  finish();
                }

                @Override
                public void failure(TwitterException e) {
                  loadLoginScreen();
                  // Continues execution
                }
              });
    } else {
      loadLoginScreen();
    }
  }
コード例 #2
0
 public void addClientUser(TwitterSession twitterSession, CreateCompletedListener addedListener) {
   ConnectionSource connectionSource = null;
   try {
     DataBaseHelper helper = new DataBaseHelper(Global.getInstance().getApplicationContext());
     connectionSource = helper.getConnectionSource();
     TableUtils.createTableIfNotExists(connectionSource, ClientUserTable.class);
     Dao<ClientUserTable, String> dao = helper.getDao(ClientUserTable.class);
     ClientUserTable table1 = dao.queryForId("" + twitterSession.getUserId());
     if (table1 == null) {
       ClientUserTable table = new ClientUserTable(twitterSession);
       dao.createOrUpdate(table);
       new ClientUser(
           clientUsers.size(),
           twitterSession,
           clientUser -> {
             clientUsers.add(clientUser);
             addedListener.completed(clientUser);
           },
           TwitterException::printStackTrace);
     } else {
       addedListener.completed(null);
     }
   } catch (SQLException e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   } finally {
     if (connectionSource != null) {
       try {
         connectionSource.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
     }
   }
 }
コード例 #3
0
 @ReactMethod
 public String getCurrentToken(final Callback callback) {
   TwitterSession session = Twitter.getSessionManager().getActiveSession();
   if (session != null) {
     TwitterAuthToken authToken = session.getAuthToken();
     String token = authToken.token;
     String secret = authToken.secret;
     if (callback != null) {
       callback.invoke(token);
     }
     return token;
   }
   if (callback != null) {
     callback.invoke(null);
   }
   return null;
 }
コード例 #4
0
 public ClientUserTable(TwitterSession twitterSession) {
   userId = twitterSession.getUserId();
   userName = twitterSession.getUserName();
   authToken = twitterSession.getAuthToken().token;
   authTokenSecret = twitterSession.getAuthToken().secret;
 }