com.twitter.sdk.android.core.TwitterCore Java Examples
The following examples show how to use
com.twitter.sdk.android.core.TwitterCore.
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: TwitterSignUpActivity.java From socialmediasignup with MIT License | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); TwitterSession activeSession = TwitterCore.getInstance().getSessionManager().getActiveSession(); if (activeSession != null) { handleSuccess(activeSession); } else { getTwitterAuthClient().authorize(this, new Callback<TwitterSession>() { @Override public void success(Result<TwitterSession> result) { startLoading(); handleSuccess(result.data); } @Override public void failure(TwitterException exception) { handleError(exception); } }); } }
Example #2
Source File: TwitterSignUpActivity.java From socialmediasignup with MIT License | 6 votes |
private void handleSuccess(final TwitterSession session) { TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient(); AccountService accountService = twitterApiClient.getAccountService(); call = accountService.verifyCredentials(false, true, true); call.enqueue(new Callback<User>() { @Override public void success(Result<User> userResult) { SocialMediaUser user = new SocialMediaUser(); User data = userResult.data; user.setUserId(String.valueOf(data.getId())); user.setAccessToken(session.getAuthToken().token); user.setProfilePictureUrl(String.format(PROFILE_PIC_URL, data.screenName)); user.setEmail(data.email != null ? data.email : ""); user.setFullName(data.name); user.setUsername(data.screenName); user.setPageLink(String.format(PAGE_LINK, data.screenName)); handleSuccess(SocialMediaSignUp.SocialMediaType.TWITTER, user); } public void failure(TwitterException error) { handleError(error); } }); }
Example #3
Source File: TwitterServiceImpl.java From twittererer with Apache License 2.0 | 6 votes |
public Observable<com.zedeff.twittererer.models.User> getMyDetails() { return Observable.create(subscriber -> { Callback<User> callback = new Callback<User>() { @Override public void success(Result<User> result) { Log.i(TAG, "Got your details, pal!"); subscriber.onNext(new com.zedeff.twittererer.models.User(result.data.name, result.data.screenName, result.data.profileImageUrl)); } @Override public void failure(TwitterException e) { Log.e(TAG, e.getMessage(), e); subscriber.onError(e); } }; getService(UserService.class).show(TwitterCore.getInstance().getSessionManager().getActiveSession().getUserId()).enqueue(callback); }); }
Example #4
Source File: TweetUiTestCase.java From twitter-kit-android with Apache License 2.0 | 6 votes |
@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 #5
Source File: TwitterAuthClient.java From twitter-kit-android with Apache License 2.0 | 6 votes |
/** * Requests authorization. * * @param activity The {@link android.app.Activity} context to use for the authorization flow. * @param callback The callback interface to invoke when authorization completes. * @throws java.lang.IllegalArgumentException if activity or callback is null. */ public void authorize(Activity activity, Callback<TwitterSession> callback) { if (activity == null) { throw new IllegalArgumentException("Activity must not be null."); } if (callback == null) { throw new IllegalArgumentException("Callback must not be null."); } if (activity.isFinishing()) { Twitter.getLogger() .e(TwitterCore.TAG, "Cannot authorize, activity is finishing.", null); } else { handleAuthorize(activity, callback); } }
Example #6
Source File: OAuthActivity.java From twitter-kit-android with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tw__activity_oauth); spinner = findViewById(R.id.tw__spinner); webView = findViewById(R.id.tw__web_view); final boolean showProgress; if (savedInstanceState != null) { showProgress = savedInstanceState.getBoolean(STATE_PROGRESS, false); } else { showProgress = true; } spinner.setVisibility(showProgress ? View.VISIBLE : View.GONE); final TwitterCore kit = TwitterCore.getInstance(); oAuthController = new OAuthController(spinner, webView, getIntent().getParcelableExtra(EXTRA_AUTH_CONFIG), new OAuth1aService(kit, new TwitterApi()), this); oAuthController.startAuth(); }
Example #7
Source File: OAuthController.java From twitter-kit-android with Apache License 2.0 | 6 votes |
/** * Package private for testing. */ Callback<OAuthResponse> newRequestTempTokenCallback() { return new Callback<OAuthResponse>() { @Override public void success(Result<OAuthResponse> result) { requestToken = result.data.authToken; final String authorizeUrl = oAuth1aService.getAuthorizeUrl(requestToken); // Step 2. Redirect user to web view to complete authorization flow. Twitter.getLogger().d(TwitterCore.TAG, "Redirecting user to web view to complete authorization flow"); setUpWebView(webView, new OAuthWebViewClient(oAuth1aService.buildCallbackUrl(authConfig), OAuthController.this), authorizeUrl, new OAuthWebChromeClient()); } @Override public void failure(TwitterException error) { Twitter.getLogger().e(TwitterCore.TAG, "Failed to get request token", error); // Create new exception that can be safely serialized since Retrofit errors may // throw a NotSerializableException. handleAuthError(AuthHandler.RESULT_CODE_ERROR, new TwitterAuthException("Failed to get request token")); } }; }
Example #8
Source File: OAuthController.java From twitter-kit-android with Apache License 2.0 | 6 votes |
private void handleWebViewSuccess(Bundle bundle) { Twitter.getLogger().d(TwitterCore.TAG, "OAuth web view completed successfully"); if (bundle != null) { final String verifier = bundle.getString(OAuthConstants.PARAM_VERIFIER); if (verifier != null) { // Step 3. Convert the request token to an access token. Twitter.getLogger().d(TwitterCore.TAG, "Converting the request token to an access token."); oAuth1aService.requestAccessToken(newRequestAccessTokenCallback(), requestToken, verifier); return; } } // If we get here, we failed to complete authorization. Twitter.getLogger().e(TwitterCore.TAG, "Failed to get authorization, bundle incomplete " + bundle, null); handleAuthError(AuthHandler.RESULT_CODE_ERROR, new TwitterAuthException("Failed to get authorization, bundle incomplete")); }
Example #9
Source File: OAuthController.java From twitter-kit-android with Apache License 2.0 | 6 votes |
/** * Package private for testing. */ Callback<OAuthResponse> newRequestAccessTokenCallback() { return new Callback<OAuthResponse>() { @Override public void success(Result<OAuthResponse> result) { final Intent data = new Intent(); final OAuthResponse response = result.data; data.putExtra(AuthHandler.EXTRA_SCREEN_NAME, response.userName); data.putExtra(AuthHandler.EXTRA_USER_ID, response.userId); data.putExtra(AuthHandler.EXTRA_TOKEN, response.authToken.token); data.putExtra(AuthHandler.EXTRA_TOKEN_SECRET, response.authToken.secret); listener.onComplete(Activity.RESULT_OK, data); } @Override public void failure(TwitterException error) { Twitter.getLogger().e(TwitterCore.TAG, "Failed to get access token", error); // Create new exception that can be safely serialized since Retrofit errors may // throw a NotSerializableException. handleAuthError(AuthHandler.RESULT_CODE_ERROR, new TwitterAuthException("Failed to get access token")); } }; }
Example #10
Source File: OAuthService.java From twitter-kit-android with Apache License 2.0 | 6 votes |
OAuthService(TwitterCore twitterCore, TwitterApi api) { this.twitterCore = twitterCore; this.api = api; userAgent = TwitterApi.buildUserAgent(CLIENT_NAME, twitterCore.getVersion()); final OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(chain -> { final Request request = chain.request().newBuilder() .header("User-Agent", getUserAgent()) .build(); return chain.proceed(request); }) .certificatePinner(OkHttpClientHelper.getCertificatePinner()) .build(); retrofit = new Retrofit.Builder() .baseUrl(getApi().getBaseHostUrl()) .client(client) .addConverterFactory(GsonConverterFactory.create()) .build(); }
Example #11
Source File: TweetRepositoryTest.java From twitter-kit-android with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { anyIds.add(anyId); mockTwitterCore = mock(TwitterCore.class); mockApiClient = mock(TwitterApiClient.class); mockStatusesService = mock(StatusesService.class, Mockito.RETURNS_MOCKS); when(mockApiClient.getStatusesService()).thenReturn(mockStatusesService); mockFavoriteService = mock(FavoriteService.class, Mockito.RETURNS_MOCKS); when(mockApiClient.getFavoriteService()).thenReturn(mockFavoriteService); when(mockTwitterCore.getApiClient(any(TwitterSession.class))).thenReturn(mockApiClient); when(mockTwitterCore.getApiClient()).thenReturn(mockApiClient); mockSessionManager = mock(SessionManager.class); when(mockSessionManager.getActiveSession()).thenReturn(mock(TwitterSession.class)); mockHandler = mock(Handler.class); tweetRepository = new TweetRepository(mockHandler, mockSessionManager, mockTwitterCore); }
Example #12
Source File: TweetComposerMainActivity.java From twitter-kit-android with Apache License 2.0 | 5 votes |
void launchComposer(Uri uri) { final TwitterSession session = TwitterCore.getInstance().getSessionManager() .getActiveSession(); final Intent intent = new ComposerActivity.Builder(TweetComposerMainActivity.this) .session(session) .image(uri) .text("Tweet from TwitterKit!") .hashtags("#twitter") .createIntent(); startActivity(intent); }
Example #13
Source File: TweetRepository.java From twitter-kit-android with Apache License 2.0 | 5 votes |
TweetRepository(Handler mainHandler, SessionManager<TwitterSession> userSessionManagers, TwitterCore twitterCore) { this.twitterCore = twitterCore; this.mainHandler = mainHandler; this.userSessionManagers = userSessionManagers; tweetCache = new LruCache<>(DEFAULT_CACHE_SIZE); formatCache = new LruCache<>(DEFAULT_CACHE_SIZE); }
Example #14
Source File: TwitterAuthClientTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { mockContext = mock(Context.class); when(mockContext.getPackageName()).thenReturn(getClass().getPackage().toString()); mockTwitterCore = mock(TwitterCore.class); mockAuthConfig = mock(TwitterAuthConfig.class); when(mockAuthConfig.getRequestCode()).thenReturn(TEST_REQUEST_CODE); mockSessionManager = mock(SessionManager.class); mockAuthState = mock(AuthState.class); mockCallback = mock(Callback.class); authClient = new TwitterAuthClient(mockTwitterCore, mockAuthConfig, mockSessionManager, mockAuthState); }
Example #15
Source File: SearchTimeline.java From twitter-kit-android with Apache License 2.0 | 5 votes |
SearchTimeline(TwitterCore twitterCore, String query, Geocode geocode, String resultType, String languageCode, Integer maxItemsPerRequest, String untilDate) { this.twitterCore = twitterCore; this.languageCode = languageCode; this.maxItemsPerRequest = maxItemsPerRequest; this.untilDate = untilDate; this.resultType = resultType; // if the query is non-null append the filter Retweets modifier this.query = query == null ? null : query + FILTER_RETWEETS; this.geocode = geocode; }
Example #16
Source File: UserTimeline.java From twitter-kit-android with Apache License 2.0 | 5 votes |
UserTimeline(TwitterCore twitterCore, Long userId, String screenName, Integer maxItemsPerRequest, Boolean includeReplies, Boolean includeRetweets) { this.twitterCore = twitterCore; this.userId = userId; this.screenName = screenName; this.maxItemsPerRequest = maxItemsPerRequest; // null includeReplies should default to false this.includeReplies = includeReplies == null ? false : includeReplies; this.includeRetweets = includeRetweets; }
Example #17
Source File: App.java From PracticeDemo with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET); // Fabric.with(this, new TwitterCore(authConfig), new Digits()); Fabric.with(this, new TwitterCore(authConfig),new TweetComposer()); }
Example #18
Source File: TweetsFragment.java From white-label-event-app with Apache License 2.0 | 5 votes |
private void initTwitterSearch() { core = TwitterCore.getInstance(); session = core.getSessionManager().getActiveSession(); if (session != null) { client = core.getApiClient(session); } else { client = core.getGuestApiClient(); } if (client != null) { doSearch(); } }
Example #19
Source File: TwitterLoginInstance.java From ShareLoginPayUtil with Apache License 2.0 | 5 votes |
@SuppressLint("CheckResult") @Override public void fetchUserInfo(final BaseToken token) { mSubscribe = Flowable.create(new FlowableOnSubscribe<TwitterUser>() { @Override public void subscribe(@NonNull FlowableEmitter<TwitterUser> userEmitter) { TwitterApiClient apiClient = TwitterCore.getInstance().getApiClient(); Call<User> userCall = apiClient.getAccountService().verifyCredentials(true, false, false); try { Response<User> execute = userCall.execute(); userEmitter.onNext(new TwitterUser(execute.body())); userEmitter.onComplete(); } catch (Exception e) { ShareLogger.e(ShareLogger.INFO.FETCH_USER_INOF_ERROR); userEmitter.onError(e); } } }, BackpressureStrategy.DROP) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<TwitterUser>() { @Override public void accept(@NonNull TwitterUser user) { mLoginListener.loginSuccess(new LoginResultData(LoginPlatform.TWITTER, token, user)); LoginUtil.recycle(); } }, new Consumer<Throwable>() { @Override public void accept(@NonNull Throwable throwable) { mLoginListener.loginFailure(new Exception(throwable), ShareLogger.INFO.ERR_FETCH_CODE); LoginUtil.recycle(); } }); }
Example #20
Source File: TwitterNetwork.java From EasyLogin with MIT License | 5 votes |
@Override public void logout() { TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession(); if (twitterSession != null) { TwitterCore.getInstance().getSessionManager().clearActiveSession(); loginButton.get().setEnabled(true); } }
Example #21
Source File: TwitterLoginButton.java From twitter-kit-android with Apache License 2.0 | 5 votes |
private void checkTwitterCoreAndEnable() { //Default (Enabled) in edit mode if (isInEditMode()) return; try { TwitterCore.getInstance(); } catch (IllegalStateException ex) { //Disable if TwitterCore hasn't started Twitter.getLogger().e(TAG, ex.getMessage()); setEnabled(false); } }
Example #22
Source File: TwitterListTimeline.java From twitter-kit-android with Apache License 2.0 | 5 votes |
TwitterListTimeline(TwitterCore twitterCore, Long listId, String slug, Long ownerId, String ownerScreenName, Integer maxItemsPerRequest, Boolean includeRetweets) { this.twitterCore = twitterCore; this.listId = listId; this.slug = slug; this.ownerId = ownerId; this.ownerScreenName = ownerScreenName; this.maxItemsPerRequest = maxItemsPerRequest; this.includeRetweets = includeRetweets; }
Example #23
Source File: TwitterListTimelineTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Before public void setUp() { twitterCore = mock(TwitterCore.class); apiClient = mock(TwitterApiClient.class); listService = mock(ListService.class, new MockCallAnswer()); when(apiClient.getListService()).thenReturn(listService); when(twitterCore.getApiClient()).thenReturn(apiClient); }
Example #24
Source File: UserTimelineTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Before public void setUp() { twitterCore = mock(TwitterCore.class); apiClient = mock(TwitterApiClient.class); statusesService = mock(StatusesService.class, new MockCallAnswer()); when(apiClient.getStatusesService()).thenReturn(statusesService); when(twitterCore.getApiClient()).thenReturn(apiClient); }
Example #25
Source File: CollectionTimelineTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { testUserMap.put(TEST_USER_1.id, TEST_USER_1); testUserMap.put(TEST_USER_2.id, TEST_USER_2); testTweetMap.put(TEST_TWEET_1.id, TEST_TWEET_1); testTweetMap.put(TEST_TWEET_2.id, TEST_TWEET_2); testTweetMap.put(TEST_TWEET_QUOTE.id, TEST_TWEET_QUOTE); // testItems order Test Tweet 1, then 2 testItems.add(new TwitterCollection.TimelineItem( new TwitterCollection.TimelineItem.TweetItem(5858L))); testItems.add(new TwitterCollection.TimelineItem( new TwitterCollection.TimelineItem.TweetItem(8585L))); testItems.add(new TwitterCollection.TimelineItem( new TwitterCollection.TimelineItem.TweetItem(858909L))); // testItemsRev orders Test Tweet 2, then 1 testItemsRev.add(new TwitterCollection.TimelineItem( new TwitterCollection.TimelineItem.TweetItem(858909L))); testItemsRev.add(new TwitterCollection.TimelineItem( new TwitterCollection.TimelineItem.TweetItem(8585L))); testItemsRev.add(new TwitterCollection.TimelineItem( new TwitterCollection.TimelineItem.TweetItem(5858L))); twitterCore = mock(TwitterCore.class); apiClient = mock(TwitterApiClient.class); collectionService = mock(CollectionService.class, new MockCallAnswer()); when(apiClient.getCollectionService()).thenReturn(collectionService); when(twitterCore.getApiClient()).thenReturn(apiClient); }
Example #26
Source File: SearchTimelineTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Before public void setUp() { twitterCore = mock(TwitterCore.class); apiClient = mock(TwitterApiClient.class); searchService = mock(SearchService.class, new MockCallAnswer()); when(apiClient.getSearchService()).thenReturn(searchService); when(twitterCore.getApiClient()).thenReturn(apiClient); }
Example #27
Source File: AuthState.java From twitter-kit-android with Apache License 2.0 | 5 votes |
public boolean beginAuthorize(Activity activity, AuthHandler authHandler) { boolean result = false; if (isAuthorizeInProgress()) { Twitter.getLogger().w(TwitterCore.TAG, "Authorize already in progress"); } else if (authHandler.authorize(activity)) { result = authHandlerRef.compareAndSet(null, authHandler); if (!result) { Twitter.getLogger().w(TwitterCore.TAG, "Failed to update authHandler, authorize" + " already in progress."); } } return result; }
Example #28
Source File: TwitterAuthClient.java From twitter-kit-android with Apache License 2.0 | 5 votes |
TwitterAuthClient(TwitterCore twitterCore, TwitterAuthConfig authConfig, SessionManager<TwitterSession> sessionManager, AuthState authState) { this.twitterCore = twitterCore; this.authState = authState; this.authConfig = authConfig; this.sessionManager = sessionManager; }
Example #29
Source File: TwitterAuthClient.java From twitter-kit-android with Apache License 2.0 | 5 votes |
private boolean authorizeUsingSSO(Activity activity, CallbackWrapper callbackWrapper) { if (SSOAuthHandler.isAvailable(activity)) { Twitter.getLogger().d(TwitterCore.TAG, "Using SSO"); return authState.beginAuthorize(activity, new SSOAuthHandler(authConfig, callbackWrapper, authConfig.getRequestCode())); } else { return false; } }
Example #30
Source File: TwitterAuthClient.java From twitter-kit-android with Apache License 2.0 | 5 votes |
/** * Call this method when {@link android.app.Activity#onActivityResult(int, int, Intent)} * is called to complete the authorization flow. * * @param requestCode the request code used for SSO * @param resultCode the result code returned by the SSO activity * @param data the result data returned by the SSO activity */ public void onActivityResult(int requestCode, int resultCode, Intent data) { Twitter.getLogger().d(TwitterCore.TAG, "onActivityResult called with " + requestCode + " " + resultCode); if (!authState.isAuthorizeInProgress()) { Twitter.getLogger().e(TwitterCore.TAG, "Authorize not in progress", null); } else { final AuthHandler authHandler = authState.getAuthHandler(); if (authHandler != null && authHandler.handleOnActivityResult(requestCode, resultCode, data)) { authState.endAuthorize(); } } }