List of usage examples for twitter4j.auth AccessToken AccessToken
public AccessToken(String token, String tokenSecret)
From source file:com.hyperkode.friendshare.fragment.TwitterListFragment.java
License:Open Source License
private void setupTwitter() { mSettings = this.getActivity().getSharedPreferences(PREFS_NAME, 0); accessToken = mSettings.getString("twitter_access_token", null); accessTokenSecret = mSettings.getString("twitter_access_token_secret", null); // Get Access Token and persist it AccessToken at = new AccessToken(accessToken, accessTokenSecret); // initialize Twitter4J twitter4j = new TwitterFactory().getInstance(); twitter4j.setOAuthConsumer(getString(R.string.TWITTER_CONSUMER_KEY), getString(R.string.TWITTER_CONSUMER_SECRET)); twitter4j.setOAuthAccessToken(at);/* ww w . ja va 2s . c o m*/ }
From source file:com.isitbusythere.reporter.TwitterSessionStore.java
License:Apache License
public static boolean restore(Twitter session, Context context) { SharedPreferences savedSession = context.getSharedPreferences(KEY, Context.MODE_PRIVATE); session.setOAuthConsumer(context.getString(R.string.TWITTER_APP_KEY), context.getString(R.string.TWITTER_APP_SECRET)); String userToken = savedSession.getString(TOKEN, null); if (userToken == null) { session = null;//w w w.ja va2 s . c o m return false; } try { session.setOAuthAccessToken(new AccessToken(userToken, savedSession.getString(SECRET, null))); } catch (IllegalStateException e) { //I don't care } return true; }
From source file:com.javielinux.twitter.ConnectionManager.java
License:Apache License
public Twitter loadUser(long id) { Twitter twitter = null;//w w w . j av a 2s .co m Entity ent = getUserById(id); if (ent != null) { // comprobamos si no es facebook /* if (ent.getString("service")!=null) { if (ent.getString("service").equals("facebook")) { ent = DataFramework.getInstance().getTopEntity("users", "service is null or service = \"twitter.com\"", ""); ent.setValue("active", 1); ent.save(); } } */ String service = ent.getString("service"); if (service.equals("")) service = "twitter.com"; //setNetworkConfig(service); String accessToken = ent.getString(KEY_AUTH_KEY); String accessTokenSecret = ent.getString(KEY_AUTH_SECRET_KEY); // ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); // configurationBuilder.setOAuthConsumerKey(accessToken); // configurationBuilder.setOAuthConsumerSecret(accessTokenSecret); // configurationBuilder.setUseSSL(true); // Configuration configuration = configurationBuilder.build(); // twitter = new TwitterFactory(configuration).getInstance(); AccessToken at = new AccessToken(accessToken, accessTokenSecret); twitter = new TwitterFactory(getConfiguration()).getInstance(at); Log.d(Utils.TAG, "Cargado " + ent.getString("name") + " desde twitter"); } return twitter; }
From source file:com.jeanchampemont.wtfdyum.service.impl.TwitterServiceImpl.java
License:Apache License
private Twitter twitter(final Principal principal) { final Twitter instance = twitter(); instance.setOAuthAccessToken(new AccessToken(principal.getToken(), principal.getTokenSecret())); return instance; }
From source file:com.lorenzobraghetto.speakbird.Logic.TwitterService.java
License:Open Source License
private AccessToken getAccessToken() { SharedPreferences settings = getSharedPreferences("Auth", MODE_PRIVATE); String token = settings.getString("accessTokenToken", ""); String tokenSecret = settings.getString("accessTokenSecret", ""); if (token != null && tokenSecret != null && !"".equals(tokenSecret) && !"".equals(token)) { return new AccessToken(token, tokenSecret); }//w w w . ja v a 2s . com return null; }
From source file:com.lorenzobraghetto.speakbird.View.Mentions.java
License:Open Source License
protected AccessToken getAccessToken() { SharedPreferences settings = mContext.getSharedPreferences("Auth", mContext.MODE_PRIVATE); String token = settings.getString("accessTokenToken", ""); String tokenSecret = settings.getString("accessTokenSecret", ""); if (token != null && tokenSecret != null && !"".equals(tokenSecret) && !"".equals(token)) { return new AccessToken(token, tokenSecret); }//w w w. j a v a 2s . com return null; }
From source file:com.lorenzobraghetto.speakbird.View.Splash.java
License:Open Source License
@Override public void onResume() { super.onResume(); if (getIntent() != null && this.getIntent().getData() != null) { Uri uri = getIntent().getData(); if (uri != null && uri.toString().startsWith("x-latify-oauth-twitter")) { getConsumerProvider();//from w w w . ja v a2 s .c o m String verifier = uri.getQueryParameter("oauth_verifier"); provider = new DefaultOAuthProvider("https://api.twitter.com/oauth/request_token", "https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/authorize"); setConsumerProvider(); try { // this will populate token and token_secret in consumer provider.retrieveAccessToken(consumer, verifier); // Get Access Token and persist it AccessToken a = new AccessToken(consumer.getToken(), consumer.getTokenSecret()); storeAccessToken(a); //accountsync Account account = new Account("Speakbird Twitter Account", "com.lorenzobraghetto.speakbird.account"); AccountManager am = AccountManager.get(this); boolean accountCreated = am.addAccountExplicitly(account, null, null); ContentResolver.setSyncAutomatically(account, "com.lorenzobraghetto.speakbird.content", true); ContentResolver.setSyncAutomatically(account, "com.lorenzobraghetto.speakbird.contentm", true); Bundle extras = ((SpeakBirdApplication) getApplication()).getExtraAccount(); if (uri.toString().contains("fromsync")) { if (extras != null) { if (accountCreated) { //Pass the new account back to the account manager AccountAuthenticatorResponse response = extras .getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE); Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, "Speakbird Twitter Account"); result.putString(AccountManager.KEY_ACCOUNT_TYPE, "com.lorenzobraghetto.speakbird.account"); response.onResult(result); } finish(); startActivity(new Intent("android.settings.SYNC_SETTINGS")); finish(); return; } } Toast.makeText(this, getString(R.string.newaccount), Toast.LENGTH_LONG).show(); Intent mainIntent = new Intent(Splash.this, Main.class); finish(); startActivity(mainIntent); } catch (Exception e) { //Log.e(APP, e.getMessage()); e.printStackTrace(); Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); Log.v("SPEAKBIRD", "SPEAKBIRD errore2 " + e.getMessage()); } } } }
From source file:com.lorenzobraghetto.speakbird.View.Splash.java
License:Open Source License
private AccessToken getAccessToken() { String token = authsettings.getString("accessTokenToken", ""); String tokenSecret = authsettings.getString("accessTokenSecret", ""); if (token != null && tokenSecret != null && !"".equals(tokenSecret) && !"".equals(token)) { return new AccessToken(token, tokenSecret); }// w w w . j a va2 s .com return null; }
From source file:com.marpies.ane.twitter.data.TwitterAPI.java
License:Apache License
public static AccessToken getAccessToken() { if (mAccessToken != null) { return mAccessToken; }//from w w w . j a v a 2s . c o m if (hasAccessTokens()) { mAccessToken = new AccessToken(getPreferences().getString("accessToken", ""), getPreferences().getString("accessTokenSecret", "")); return mAccessToken; } return null; }
From source file:com.mastfrog.acteur.twitter.TwitterSign.java
@SuppressWarnings("unchecked") RemoteUserInfo zgetUserInfo(String oauth_nonce, TwitterOAuthPlugin.TwitterToken credential, AuthorizationResponse auth)//from w w w .j a va2s .c o m throws UnsupportedEncodingException, GeneralSecurityException, InterruptedException, IOException { System.setProperty("twitter4j.http.useSSL", "false"); Twitter twitter = TwitterFactory.getSingleton(); try { // Idiotic - shutdown does not clear state twitter.setOAuthConsumer(twitter_consumer_key, twitter_consumer_secret); } catch (Exception e) { e.printStackTrace(); } twitter.setOAuthAccessToken(new AccessToken(auth.accessToken, auth.accessTokenSecret)); OAuthAuthorization a = new OAuthAuthorization(twitter.getConfiguration()); a.setOAuthConsumer(twitter_consumer_key, twitter_consumer_secret); URL url = URL.builder(Protocols.HTTPS) // URL url = URL.builder(Protocols.HTTP) // XXX NOT UNENCRYPTED! JUST FOR DEBUGING .setHost(Host.parse("api.twitter.com")).setPath("1.1/account/verify_credentials.json").create(); String hdr = new SigBuilder().add(oauth_token, auth.accessToken).add(OAuthHeaders.oauth_nonce, oauth_nonce) .toHeader(Method.GET, url.getPathAndQuery(), auth); // XXX encode URL? String franken = a.xgenerateAuthorizationHeader(oauth_nonce, "GET", "/1.1/account/verify_credentials.json", new HttpParameter[0], new twitter4j.auth.AccessToken(auth.accessToken, auth.accessTokenSecret)); OAuthAuthorization oa = new OAuthAuthorization(twitter.getConfiguration()); oa.setOAuthConsumer(twitter_consumer_key, twitter_consumer_secret); oa.setOAuthAccessToken(new AccessToken(auth.accessToken, auth.accessTokenSecret)); twitter4j.internal.http.HttpRequest r = new twitter4j.internal.http.HttpRequest(RequestMethod.GET, "https://api.twitter.com/twitter4j.internal.http.HttpRequest", new HttpParameter[0], oa, Collections.<String, String>emptyMap()); ResponseLatch latch = new ResponseLatch(); RH rh = new RH(); client.get().setURL(url).addHeader(Headers.stringHeader("Authorization"), hdr) .addHeader(Headers.stringHeader("X-Twitter-Client-URL"), "http://twitter4j.org/en/twitter4j-3.0.4-SNAPSHOT.xml") .addHeader(Headers.stringHeader("X-Twitter-Client"), "Twitter4J") .addHeader(Headers.stringHeader("Accept-Encoding"), "gzip") .addHeader(Headers.stringHeader("X-Twitter-Client-Version"), "3.0.4-SNAPSHOT") .addHeader(Headers.stringHeader("Accept"), "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2") // .addHeader(Headers.stringHeader("Accept"), "*/*") // .addHeader(Headers.stringHeader("Connection"), "keep-alive") .noDateHeader() // .noConnectionHeader() // .addHeader(Headers.stringHeader("Content-Type"), "application/x-www-form-urlencoded") // .setBody("screen_name=kablosna", MediaType.PLAIN_TEXT_UTF_8) .on(StateType.Closed, latch).on(StateType.Timeout, latch).execute(rh); rh.await(1, TimeUnit.MINUTES); latch.latch.await(1, TimeUnit.MINUTES); String responseBody = rh.getResponse(); RUI rui = new RUI(); if (responseBody == null) { // System.out.println("NULL RESPONSE BODY."); throw new IOException(rh.toString()); } rui.putAll(new ObjectMapper().readValue(responseBody, Map.class)); return rui; }