当前位置: 首页>>代码示例>>Java>>正文


Java TwitterAuthToken类代码示例

本文整理汇总了Java中com.twitter.sdk.android.core.TwitterAuthToken的典型用法代码示例。如果您正苦于以下问题:Java TwitterAuthToken类的具体用法?Java TwitterAuthToken怎么用?Java TwitterAuthToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TwitterAuthToken类属于com.twitter.sdk.android.core包,在下文中一共展示了TwitterAuthToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupTwitterLogin

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
private void setupTwitterLogin() {
    //TODO: Check if twitter login is actvated in the server
    if (!TextUtils.isEmpty(BuildConfig.TWITTER_KEY)) {
        mTwitterButton.setCallback(new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {
                TwitterAuthToken authToken = result.data.getAuthToken();
                //ATENTION: this is not working
                // see https://github.com/RocketChat/Rocket.Chat/issues/1484
                mRxRocketMethods.loginWithOAuth(authToken.token, authToken.secret);
            }

            @Override
            public void failure(TwitterException exception) {
                Log.d("TwitterKit", "Login with Twitter failure", exception);
            }
        });
    } else {
        mTwitterButton.setVisibility(View.GONE);
    }
}
 
开发者ID:lukamarin,项目名称:Rocket.Chat-android,代码行数:22,代码来源:LoginActivity.java

示例2: setUp

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    session = new DigitsSession(new TwitterAuthToken(TestConstants.TOKEN,
            TestConstants.SECRET), TestConstants.USER_ID, TestConstants.PHONE,
            TestConstants.EMAIL);
    mockSessionManager = mock(SessionManager.class);
    details = new DigitsEventDetailsBuilder()
            .withAuthStartTime(1L)
            .withLanguage("en")
            .withCountry("US");

    when(mockSessionManager.getActiveSession()).thenReturn(session);
    callback = mock(WeakAuthCallback.class);
    bundle = new Bundle();
    bundle.putString(LoginResultReceiver.KEY_ERROR, ERROR);
    bundle.putParcelable(DigitsClient.EXTRA_EVENT_DETAILS_BUILDER, details);
    digitsErrorCaptor = ArgumentCaptor.forClass(DigitsException.class);
    sessionCaptor = ArgumentCaptor.forClass(DigitsSession.class);
    detailsArgumentCaptor = ArgumentCaptor.forClass(DigitsEventDetails.class);
    collector = mock(DigitsEventCollector.class);
}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:22,代码来源:LoginResultReceiverTests.java

示例3: testCreate_user

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
@Test
public void testCreate_user() throws Exception {
    final ArrayList<Header> headers = new ArrayList<>();
    headers.add(new Header(ANY_HEADER, ANY_DATA));
    headers.add(new Header(DigitsSession.TOKEN_HEADER, TestConstants.TOKEN));
    headers.add(new Header(DigitsSession.SECRET_HEADER, TestConstants.SECRET));

    final Response response = new Response(TestConstants.TWITTER_URL,
            HttpURLConnection.HTTP_ACCEPTED, "", headers, null);
    final DigitsUser user = new DigitsUser(TestConstants.USER_ID,
            DigitsSession.DEFAULT_PHONE_NUMBER);
    final DigitsSession session = DigitsSession.create(new Result<>(user, response),
            TestConstants.PHONE);
    final DigitsSession newSession = new DigitsSession(new TwitterAuthToken(TestConstants.TOKEN,
            TestConstants.SECRET),
            TestConstants.USER_ID, TestConstants.PHONE, DigitsSession.DEFAULT_EMAIL);
    assertEquals(session, newSession);
}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:19,代码来源:DigitsSessionTests.java

示例4: testSuccess_phoneChanged

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
@Test
public void testSuccess_phoneChanged() throws Exception {
    final DigitsSession changedSession =
            new DigitsSession(new TwitterAuthToken(TestConstants.TOKEN, TestConstants.SECRET),
                    TestConstants.USER_ID, TestConstants.ES_RAW_PHONE, TestConstants.EMAIL);
    when(sessionManager.getSession(TestConstants.USER_ID)).thenReturn(changedSession);

    verificationCallback.addSessionListener(sessionListener);
    verificationCallback.addSessionListener(sessionListener2);
    verificationCallback.success(result);

    verify(sessionManager).setSession(TestConstants.USER_ID,
            DigitsSession.create(result.data));
    verify(sessionListener).changed(any(DigitsSession.class));
    verify(sessionListener2).changed(any(DigitsSession.class));
}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:17,代码来源:VerificationCallbackTest.java

示例5: ScribeClient

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param context the context
 * @param executor scheduled executor service for executing scribe requests on background thread
 * @param scribeConfig the scribe configuration
 * @param transform the scribe event transform for serializing and deserializing scribe events
 * flush of all queued events as long as a network connection is available.
 * @param authConfig the auth configuration
 * @param sessionManager the session manager
 * @param idManager the id manager used to provide the device id
 */
public ScribeClient(Context context, ScheduledExecutorService executor,
        ScribeConfig scribeConfig, ScribeEvent.Transform transform,
        TwitterAuthConfig authConfig,
        SessionManager<? extends Session<TwitterAuthToken>> sessionManager,
        GuestSessionProvider guestSessionProvider, IdManager idManager) {
    this.context = context;
    this.executor = executor;
    this.scribeConfig = scribeConfig;
    this.transform = transform;
    this.authConfig = authConfig;
    this.sessionManager = sessionManager;
    this.guestSessionProvider = guestSessionProvider;
    this.idManager = idManager;

    // Set initial capacity to 2 to handle one logged in user and one logged out user.
    scribeHandlers = new ConcurrentHashMap<>(2);
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:30,代码来源:ScribeClient.java

示例6: parseAuthResponse

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
/**
 * @return  {@link OAuthResponse} parsed from the
 * response, may be {@code null} if the response does not contain an auth token and secret.
 */
public static OAuthResponse parseAuthResponse(String response) {
    final TreeMap<String, String> params = UrlUtils.getQueryParams(response, false);
    final String token = params.get(OAuthConstants.PARAM_TOKEN);
    final String secret = params.get(OAuthConstants.PARAM_TOKEN_SECRET);
    final String userName = params.get(PARAM_SCREEN_NAME);
    final long userId;
    if (params.containsKey(PARAM_USER_ID)) {
        userId = Long.parseLong(params.get(PARAM_USER_ID));
    } else {
        userId = 0L;
    }
    if (token == null || secret == null) {
        return null;
    } else {
        return new OAuthResponse(new TwitterAuthToken(token, secret), userName, userId);
    }
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:22,代码来源:OAuth1aService.java

示例7: handleOnActivityResult

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
/**
 * Called when {@link android.app.Activity#onActivityResult(int, int, android.content.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 boolean handleOnActivityResult(int requestCode, int resultCode, Intent data) {
    if (this.requestCode != requestCode) {
        return false;
    }

    final Callback<TwitterSession> callback = getCallback();
    if (callback != null) {
        if (resultCode == Activity.RESULT_OK) {
            final String token = data.getStringExtra(EXTRA_TOKEN);
            final String tokenSecret = data.getStringExtra(EXTRA_TOKEN_SECRET);
            final String screenName = data.getStringExtra(EXTRA_SCREEN_NAME);
            final long userId = data.getLongExtra(EXTRA_USER_ID, 0L);
            callback.success(new Result<>(new TwitterSession(
                    new TwitterAuthToken(token, tokenSecret), userId, screenName), null));
        } else if (data != null && data.hasExtra(EXTRA_AUTH_ERROR)) {
            callback.failure(
                    (TwitterAuthException) data.getSerializableExtra(EXTRA_AUTH_ERROR));
        } else {
            callback.failure(new TwitterAuthException("Authorize failed."));
        }
    }
    return true;
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:32,代码来源:AuthHandler.java

示例8: testRequestAccessToken

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
@Test
public void testRequestAccessToken() {
    final TwitterAuthToken token = new TwitterAuthToken("token", "secret");
    final String verifier = "verifier";
    service.api = new MockOAuth1aService() {
        @Override
        public Call<ResponseBody> getAccessToken(@Header(OAuthConstants.HEADER_AUTHORIZATION) String auth,
                                                 @Query(OAuthConstants.PARAM_VERIFIER) String innerVerifier) {

            assertEquals(verifier, innerVerifier);
            assertNotNull(auth);
            assertTrue(auth.contains(token.token));

            return super.getAccessToken(auth, innerVerifier);
        }
    };
    service.requestAccessToken(mock(Callback.class), token, verifier);
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:19,代码来源:OAuth1aServiceTest.java

示例9: testHandleOnActivityResult_resultCodeOK

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
@Test
public void testHandleOnActivityResult_resultCodeOK() {
    // Verify that when handleOnActivityResult is called with ok, the listener receives the auth
    // response.
    final Callback<TwitterSession> mockCallback = mock(Callback.class);
    final AuthHandler authHandler = newAuthHandler(mockCallback);

    final boolean result = authHandler.handleOnActivityResult(TEST_REQUEST_CODE,
            Activity.RESULT_OK, new Intent()
                    .putExtra(AuthHandler.EXTRA_TOKEN, TestFixtures.TOKEN)
                    .putExtra(AuthHandler.EXTRA_TOKEN_SECRET, TestFixtures.SECRET)
                    .putExtra(AuthHandler.EXTRA_SCREEN_NAME, TestFixtures.SCREEN_NAME)
                    .putExtra(AuthHandler.EXTRA_USER_ID, TestFixtures.USER_ID));

    assertTrue(result);
    final ArgumentCaptor<Result> argCaptor = ArgumentCaptor.forClass(Result.class);
    verify(mockCallback).success(argCaptor.capture());
    final TwitterSession session = (TwitterSession) argCaptor.getValue().data;
    final TwitterAuthToken authToken = session.getAuthToken();
    assertEquals(TestFixtures.TOKEN, authToken.token);
    assertEquals(TestFixtures.SECRET, authToken.secret);
    assertEquals(TestFixtures.SCREEN_NAME, session.getUserName());
    assertEquals(TestFixtures.USER_ID, session.getUserId());
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:25,代码来源:AuthHandlerTest.java

示例10: testNewAccessTokenCallback_success

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
@Test
public void testNewAccessTokenCallback_success() {
    final Callback<OAuthResponse> callback = controller.newRequestAccessTokenCallback();
    final OAuthResponse oAuthResponse = new OAuthResponse(
            new TwitterAuthToken(TestFixtures.TOKEN, TestFixtures.SECRET),
            TestFixtures.SCREEN_NAME, TestFixtures.USER_ID);
    callback.success(new Result<>(oAuthResponse, null));

    final ArgumentCaptor<Intent> intentArgCaptor = ArgumentCaptor.forClass(Intent.class);
    verify(mockListener).onComplete(eq(Activity.RESULT_OK), intentArgCaptor.capture());
    final Intent data = intentArgCaptor.getValue();
    assertEquals(TestFixtures.SCREEN_NAME, data.getStringExtra(AuthHandler.EXTRA_SCREEN_NAME));
    assertEquals(TestFixtures.USER_ID, data.getLongExtra(AuthHandler.EXTRA_USER_ID, 0L));
    assertEquals(TestFixtures.TOKEN, data.getStringExtra(AuthHandler.EXTRA_TOKEN));
    assertEquals(TestFixtures.SECRET, data.getStringExtra(AuthHandler.EXTRA_TOKEN_SECRET));
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:17,代码来源:OAuthControllerTest.java

示例11: onCreate

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final TwitterAuthToken token = intent.getParcelableExtra(EXTRA_USER_TOKEN);
    final TwitterSession session = new TwitterSession(token, PLACEHOLDER_ID,
            PLACEHOLDER_SCREEN_NAME);
    final Uri imageUri = intent.getParcelableExtra(EXTRA_IMAGE_URI);
    final String text = intent.getStringExtra(EXTRA_TEXT);
    final String hashtags = intent.getStringExtra(EXTRA_HASHTAGS);
    final int themeResId = intent.getIntExtra(EXTRA_THEME, R.style.ComposerLight);

    setTheme(themeResId);
    setContentView(R.layout.tw__activity_composer);
    final ComposerView composerView = findViewById(R.id.tw__composer_view);
    composerController = new ComposerController(composerView, session, imageUri, text, hashtags,
            new FinisherImpl());
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:20,代码来源:ComposerActivity.java

示例12: setUp

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    mockComposerView = mock(ComposerView.class);
    mockContext = mock(Context.class);
    when(mockComposerView.getContext()).thenReturn(mockContext);

    mockFinisher = mock(ComposerActivity.Finisher.class);
    mockAuthToken = mock(TwitterAuthToken.class);
    mockTwitterSession = mock(TwitterSession.class);
    when(mockTwitterSession.getAuthToken()).thenReturn(mockAuthToken);

    final TwitterApiClient mockTwitterApiClient = mock(TwitterApiClient.class);
    mockAccountService = mock(AccountService.class);
    when(mockAccountService
            .verifyCredentials(any(Boolean.class), any(Boolean.class), any(Boolean.class)))
            .thenReturn(mock(Call.class));
    when(mockTwitterApiClient.getAccountService()).thenReturn(mockAccountService);

    mockComposerScribeClient = mock(ComposerScribeClient.class);

    mockDependencyProvider = mock(ComposerController.DependencyProvider.class);
    when(mockDependencyProvider.getApiClient(any(TwitterSession.class)))
            .thenReturn(mockTwitterApiClient);
    when(mockDependencyProvider.getTweetValidator()).thenReturn(new Validator());
    when(mockDependencyProvider.getScribeClient()).thenReturn(mockComposerScribeClient);
}
 
开发者ID:twitter,项目名称:twitter-kit-android,代码行数:27,代码来源:ComposerControllerTest.java

示例13: handleResult

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
private JSONObject handleResult(DigitsSession result, String phoneNumber) {
	JSONObject response = new JSONObject();
	try {
		TwitterAuthToken authToken = (TwitterAuthToken) result
				.getAuthToken();
		
		DigitsOAuthSigning oauthSigning = new DigitsOAuthSigning(authConfig, authToken);
		
		response.put("userId", result.getId());
		response.put("secret", authToken.secret);
		response.put("token", authToken.token);
		response.put("phoneNumber", phoneNumber);
		
		response.put("verifyCredentialsAuthHeader", oauthSigning.getOAuthEchoHeadersForVerifyCredentials().get("X-Verify-Credentials-Authorization"));
		
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return response;
}
 
开发者ID:nifino,项目名称:twitter-digits-plugin,代码行数:21,代码来源:TwitterDigits.java

示例14: onCreate

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig));

    setContentView(R.layout.activity_main);

    loginButton = (TwitterLoginButton) findViewById(R.id.login_button);
    loginButton.setCallback(new Callback<TwitterSession>() {

        @Override
        public void success(Result<TwitterSession> result) {
            TwitterSession session = Twitter.getSessionManager().getActiveSession();

            long userId = session.getUserId();
            String userName = session.getUserName();

            TwitterAuthToken authToken = session.getAuthToken();
            String token = authToken.token;
            String secret = authToken.secret;
        }

        @Override
        public void failure(TwitterException exception) {
            // Do something on failure
        }
    });
}
 
开发者ID:micromasterandroid,项目名称:androidadvanced,代码行数:30,代码来源:MainActivity.java

示例15: getToken

import com.twitter.sdk.android.core.TwitterAuthToken; //导入依赖的package包/类
public String getToken() {
    if (Prefs.getString(SyncMaster.GLOBAL_TOKEN, null) != null) {
        return Prefs.getString(SyncMaster.GLOBAL_TOKEN, null);
    } else if (AccessToken.getCurrentAccessToken() != null)
        return AccessToken.getCurrentAccessToken().getToken();
    else if (Twitter.getSessionManager().getActiveSession() != null) {
        TwitterSession session = Twitter.getSessionManager().getActiveSession();
        TwitterAuthToken authToken = session.getAuthToken();
        return authToken.token;
    } else
        return VKAccessToken.currentToken().accessToken;
}
 
开发者ID:KKorvin,项目名称:uPods-android,代码行数:13,代码来源:LoginMaster.java


注:本文中的com.twitter.sdk.android.core.TwitterAuthToken类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。