com.twitter.sdk.android.core.TwitterConfig Java Examples

The following examples show how to use com.twitter.sdk.android.core.TwitterConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactTwitterKitPackage.java    From react-native-twitterkit with MIT License 6 votes vote down vote up
public void initFabric(Context reactContext) {
  if (consumerKey == null || consumerSecret == null) {
    return;
  }

  TwitterAuthConfig authConfig
          = new TwitterAuthConfig(consumerKey, consumerSecret);

  final TwitterConfig config = new TwitterConfig.Builder(reactContext)
          .twitterAuthConfig(authConfig)
          .debug(true)
          .build();
  Twitter.initialize(config);
  new Thread(new Runnable() {
    @Override
    public void run() {
      TweetUi.getInstance();
      Log.i("ReactTwitterKit", "TweetUi instance initialized");
    }
  }).start();
}
 
Example #2
Source File: LoginActivity.java    From Simple-Blog-App with MIT License 6 votes vote down vote up
private void twitter() {
    TwitterConfig config = new TwitterConfig.Builder(this)
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(new TwitterAuthConfig(getResources().getString(R.string.com_twitter_sdk_android_CONSUMER_KEY), getResources().getString(R.string.com_twitter_sdk_android_CONSUMER_SECRET)))
            .debug(true)
            .build();
    Twitter.initialize(config);
    twitterLoginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            Log.d(TAG, "twitterLogin:success" + result);
            handleTwitterSession(result.data);
        }

        @Override
        public void failure(TwitterException exception) {
            Log.w(TAG, "twitterLogin:failure", exception);

        }
    });
}
 
Example #3
Source File: TweetUiTestCase.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    createMocks();

    // Initialize Fabric with mock executor so that kit#doInBackground() will not be called
    // during kit initialization.
    final TwitterConfig config = new TwitterConfig.Builder(getContext())
            .logger(new DefaultLogger(Log.DEBUG))
            .executorService(mock(ThreadPoolExecutor.class))
            .build();

    Twitter.initialize(config);

    final TwitterCore twitterCore = TwitterCoreTestUtils.createTwitterCore(
            new TwitterAuthConfig("", ""), clients, apiClient);

    tweetUi = TweetUi.getInstance();
    final TweetRepository tweetRepository = new TweetRepository(mainHandler,
            mock(SessionManager.class), twitterCore);
    tweetUi.setTweetRepository(tweetRepository);
    tweetUi.setImageLoader(picasso);
}
 
Example #4
Source File: TwitterLoginButtonTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
public void testOnClick_activityNullDebuggableTrue() throws Exception {
    Twitter.initialize(new TwitterConfig.Builder(getContext())
            .executorService(mock(ExecutorService.class))
            .debug(true)
            .build());
    loginButton = new TwitterLoginButton(getContext(), null, 0, mockAuthClient) {
        // This is to allow us to test TwitterLoginButton without having to set up a real
        // activity.
        @Override
        protected Activity getActivity() {
            return null;
        }
    };
    loginButton.setCallback(mockCallback);

    try {
        loginButton.performClick();
        fail("onClick should throw an exception when called and there is no activity");
    } catch (IllegalStateException e) {
        assertEquals(TwitterLoginButton.ERROR_MSG_NO_ACTIVITY, e.getMessage());
    } finally {
        TwitterCoreTestUtils.resetTwitterCore();
        TwitterTestUtils.resetTwitter();
    }
}
 
Example #5
Source File: TwitterLoginButtonTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
public void testGetTwitterAuthClient() throws Exception {
    try {
        Twitter.initialize(new TwitterConfig.Builder(getContext())
                .executorService(mock(ExecutorService.class))
                .build());

        final TwitterLoginButton button = new TwitterLoginButton(getContext()) {
            @Override
            protected Activity getActivity() {
                return mock(Activity.class);
            }
        };
        final TwitterAuthClient client = button.getTwitterAuthClient();
        assertNotNull(client);

    } finally {
        TwitterCoreTestUtils.resetTwitterCore();
        TwitterTestUtils.resetTwitter();
    }
}
 
Example #6
Source File: TwitterLoginButtonTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
public void testGetTwitterAuthClient_duplicateCalls() throws Exception {
    try {
        Twitter.initialize(new TwitterConfig.Builder(getContext())
                .executorService(mock(ExecutorService.class))
                .build());

        final TwitterLoginButton button = new TwitterLoginButton(getContext()) {
            @Override
            protected Activity getActivity() {
                return mock(Activity.class);
            }
        };
        final TwitterAuthClient client = button.getTwitterAuthClient();
        final TwitterAuthClient client2 = button.getTwitterAuthClient();
        assertSame(client, client2);

    } finally {
        TwitterCoreTestUtils.resetTwitterCore();
        TwitterTestUtils.resetTwitter();
    }
}
 
Example #7
Source File: TwitterLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
public TwitterLoginInstance(Activity activity, final LoginListener listener,
                            final boolean fetchUserInfo) {
    super(activity, listener, fetchUserInfo);

    TwitterConfig config = new TwitterConfig.Builder(activity)
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(new TwitterAuthConfig(ShareManager.CONFIG.getTwitterConsumerKey(),
                    ShareManager.CONFIG.getTwitterConsumerSecret()))
            .debug(BuildConfig.DEBUG).build();

    Twitter.initialize(config);
    mTwitterAuthClient = new TwitterAuthClient();
}
 
Example #8
Source File: SocialMediaSignUp.java    From socialmediasignup with MIT License 5 votes vote down vote up
private void initTwitter(Context appContext) {
    String consumerKey = SocialMediaSignUpUtils.getMetaDataValue(appContext, appContext.getString(R.string.com_ahmedadel_socialmediasignup_twitterConsumerKey));
    String consumerSecret = SocialMediaSignUpUtils.getMetaDataValue(appContext, appContext.getString(R.string.com_ahmedadel_socialmediasignup_twitterConsumerSecret));

    if (consumerKey != null && consumerSecret != null) {
        TwitterConfig twitterConfig = new TwitterConfig.Builder(appContext)
                .twitterAuthConfig(new TwitterAuthConfig(consumerKey, consumerSecret))
                .build();
        Twitter.initialize(twitterConfig);
    }
}
 
Example #9
Source File: TwitterNetwork.java    From EasyLogin with MIT License 5 votes vote down vote up
public TwitterNetwork(Activity activity, String consumerKey, String consumerSecret) {
    TwitterAuthConfig authConfig = new TwitterAuthConfig(consumerKey, consumerSecret);
    TwitterConfig config = new TwitterConfig.Builder(activity.getApplicationContext())
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(authConfig)
            .build();
    Twitter.initialize(config);
}
 
Example #10
Source File: TweetUiBackgroundTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    // Set a mock thread pool executor so we can run these tests knowing that doInBackground
    // has not been run.
    Twitter.initialize(new TwitterConfig.Builder(getInstrumentation().getTargetContext())
            .executorService(mock(ThreadPoolExecutor.class))
            .build());
}
 
Example #11
Source File: TweetUiTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    Twitter.initialize(new TwitterConfig.Builder(getContext())
            .executorService(mock(ExecutorService.class))
            .build());

    tweetUi = new TweetUi();
}
 
Example #12
Source File: TwitterLoginButtonTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
public void testOnClick_callbackNullDebuggableTrue() throws Exception {
    Twitter.initialize(new TwitterConfig.Builder(getContext())
            .executorService(mock(ExecutorService.class))
            .debug(true)
            .build());
    try {
        loginButton.performClick();
        fail("onClick should throw an exception when called and there is no callback");
    } catch (IllegalStateException e) {
        assertEquals("Callback must not be null, did you call setCallback?", e.getMessage());
    } finally {
        TwitterCoreTestUtils.resetTwitterCore();
        TwitterTestUtils.resetTwitter();
    }
}
 
Example #13
Source File: TwitterLoginButtonTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
private TwitterConfig setUpLogTest() {
    final Logger mockLogger = mock(Logger.class);
    when(mockLogger.isLoggable(TwitterCore.TAG, Log.WARN)).thenReturn(true);

    final TwitterConfig config = new TwitterConfig.Builder(getContext())
            .executorService(mock(ExecutorService.class))
            .logger(mockLogger)
            .build();

    return config;
}
 
Example #14
Source File: OAuthActivityTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    context = getInstrumentation().getTargetContext();
    Twitter.initialize(new TwitterConfig.Builder(context)
            .executorService(mock(ExecutorService.class))
            .build());
    mockController = mock(TestOAuthController.class);
}
 
Example #15
Source File: TweetComposerTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
public void setUp() throws Exception {
    super.setUp();
    Twitter.initialize(new TwitterConfig.Builder(getContext())
            .executorService(mock(ThreadPoolExecutor.class))
            .build());
    tweetComposer = new TweetComposer();
    tweetComposer.instance = tweetComposer;
}
 
Example #16
Source File: App.java    From twittererer with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    JodaTimeAndroid.init(this);

    Fabric.with(this, new Crashlytics());
    Twitter.initialize(new TwitterConfig.Builder(this).twitterAuthConfig(new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET)).build());

    applicationComponent = DaggerApp_ApplicationComponent.builder()
            .applicationModule(new ApplicationModule(this))
            .build();
}