本文整理汇总了Java中com.twitter.sdk.android.core.TwitterCore类的典型用法代码示例。如果您正苦于以下问题:Java TwitterCore类的具体用法?Java TwitterCore怎么用?Java TwitterCore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TwitterCore类属于com.twitter.sdk.android.core包,在下文中一共展示了TwitterCore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this,
new TwitterCore(
new TwitterAuthConfig(
getString(R.string.CONSUMER_KEY),
getString(R.string.CONSUMER_SECRET))),
new Digits.Builder().build());
Digits.authenticate(new AuthConfig.Builder().withAuthCallBack(new AuthCallback() {
@Override
public void success(DigitsSession session, String phoneNumber) {
Toast.makeText(TestDigitsActivity.this, "Digits sign in success " + phoneNumber,
Toast.LENGTH_LONG).show();
}
@Override
public void failure(DigitsException error) {
Toast.makeText(TestDigitsActivity.this, "Digits sign in failed ", Toast.LENGTH_LONG)
.show();
}
}).build());
}
示例2: endSession
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
@Override
public void endSession() {
if (AccessToken.getCurrentAccessToken() != null) {
LoginManager.getInstance().logOut();
}
TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession();
if (twitterSession != null) {
clearCookies(getApplicationContext());
Twitter.getSessionManager().clearActiveSession();
Twitter.logOut();
}
startActivity(LoginActivity.makeIntent(this));
finish();
}
示例3: createTweet
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
private void createTweet() {
// this block uses the new Twitter Kit 3 native Tweet Composer
// that does not require the Twitter app to be installed
final Intent intent = new ComposerActivity.Builder(this)
.session(TwitterCore.getInstance().getSessionManager().getActiveSession())
.hashtags(getString(R.string.hashtag))
.createIntent();
startActivity(intent);
// to use the richer Composer from the Twitter app, uncomment this block
// and remove the five lines above
//
// final TweetComposer.Builder builder =
// new TweetComposer.Builder(this).text(getApplicationContext().getResources()
// .getString(R.string.hashtag));
// builder.show();
}
示例4: follow
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
private void follow(String userHandle) {
MyTwitterApiClient mtac = new MyTwitterApiClient(TwitterCore.getInstance().getSessionManager().getActiveSession());
Call<User> call = mtac.getFriendshipsService().create(userHandle, null, false);
call.enqueue(new Callback<User>() {
@Override
public void success(Result<User> result) {
Toast.makeText(MainActivity.this,
getResources().getString(R.string.toast_follow_user_success) + " @" + result.data.screenName,
Toast.LENGTH_SHORT).show();
}
@Override
public void failure(TwitterException e) {
Toast.makeText(MainActivity.this,
getResources().getString(R.string.toast_follow_user_error),
Toast.LENGTH_SHORT).show();
}
});
}
示例5: DigitsApiClientManager
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
DigitsApiClientManager(TwitterCore twitterCore,
ExecutorService executorService,
SessionManager<DigitsSession> sessionManager,
DigitsApiClient apiClient,
DigitsRequestInterceptor interceptor,
SandboxConfig sandboxConfig) {
if (twitterCore == null) {
throw new IllegalArgumentException("twitter must not be null");
}
if (sessionManager == null) {
throw new IllegalArgumentException("sessionManager must not be null");
}
this.twitterCore = twitterCore;
this.executorService = executorService;
this.sessionManager = sessionManager;
this.interceptor = interceptor;
this.sandboxConfig = sandboxConfig;
if (apiClient != null) {
this.digitsApiClient = apiClient;
} else {
this.digitsApiClient = createNewClient();
}
}
示例6: testGetDigitClients_multipleThreads
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
public void testGetDigitClients_multipleThreads() throws Exception {
try {
Fabric.with(getContext(), new TwitterCore(new TwitterAuthConfig("", "")), new Digits());
final List<DigitsClientCallable> callables = Arrays.asList(
new DigitsClientCallable(),
new DigitsClientCallable());
final ExecutorService executorService = Executors.newFixedThreadPool(callables.size());
final List<Future<DigitsClient>> digitsClients = executorService.invokeAll(callables);
assertNotNull(digitsClients.get(0).get());
assertNotNull(digitsClients.get(1).get());
assertSame(digitsClients.get(0).get(), digitsClients.get(1).get());
} finally {
FabricTestUtils.resetFabric();
}
}
示例7: testGetDigitsClient
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
public void testGetDigitsClient() throws Exception {
try {
final Fabric fabric = new Fabric.Builder(getContext())
.kits(new Digits(), new TwitterCore(new TwitterAuthConfig("", "")))
.build();
FabricTestUtils.with(fabric);
final DigitsAuthButton authButton = new DigitsAuthButton(getContext());
assertNull(authButton.digitsClient);
authButton.setCallback(callback);
authButton.getDigitsClient();
assertNotNull(authButton.digitsClient);
} finally {
FabricTestUtils.resetFabric();
}
}
示例8: setUp
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
@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);
}
示例9: setUp
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
@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);
}
示例10: OAuthService
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
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();
}
示例11: onCreate
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
@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();
}
示例12: authorize
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
/**
* 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);
}
}
示例13: newRequestTempTokenCallback
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
/**
* 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"));
}
};
}
示例14: handleWebViewSuccess
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
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"));
}
示例15: newRequestAccessTokenCallback
import com.twitter.sdk.android.core.TwitterCore; //导入依赖的package包/类
/**
* 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"));
}
};
}