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


Java AccessToken类代码示例

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


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

示例1: getTwitterOAuthTokenAndLogin

import twitter4j.auth.AccessToken; //导入依赖的package包/类
private void getTwitterOAuthTokenAndLogin(final RequestToken requestToken, final String oauthVerifier) {
    // once a user authorizes the application, get the auth token and return to the MainActivity
    new AsyncTask<Void, Void, AccessToken>() {
        @Override
        protected AccessToken doInBackground(Void... params) {
            AccessToken accessToken = null;
            try {
                accessToken = mTwitter.getOAuthAccessToken(requestToken, oauthVerifier);
            } catch (TwitterException te) {
                Log.e(TAG, te.toString());
            }
            return accessToken;
        }

        @Override
        protected void onPostExecute(AccessToken token) {
            Intent resultIntent = new Intent();
            resultIntent.putExtra("oauth_token", token.getToken());
            resultIntent.putExtra("oauth_token_secret", token.getTokenSecret());
            resultIntent.putExtra("user_id", token.getUserId() + "");
            setResult(MainActivity.RC_TWITTER_LOGIN, resultIntent);
            finish();
        }
    }.execute();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:TwitterOAuthActivity.java

示例2: printAccessToken

import twitter4j.auth.AccessToken; //导入依赖的package包/类
void printAccessToken() {
    try {
        TwitterCredentials creds = TwitterFeed.readCredentials();
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(creds.getConsumerKey(), creds.getConsumerSecret());
        RequestToken requestToken = twitter.getOAuthRequestToken();
        System.out.println("Authorization URL: \n" + requestToken.getAuthorizationURL());
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        System.out.print("Hit above Authorization URL and Input PIN here: ");
        String pin = br.readLine();
        
        AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, pin);
        
        System.out.println("Access Token: " + accessToken.getToken());
        System.out.println("Access Token Secret: " + accessToken.getTokenSecret());
    } catch (TwitterException | IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:arun-gupta,项目名称:tweet-analysis,代码行数:22,代码来源:AccessTokenCredentials.java

示例3: main

import twitter4j.auth.AccessToken; //导入依赖的package包/类
public static void main(String[] args) {

		try {
			Twitter twitter = new TwitterFactory().getInstance();

			twitter.setOAuthConsumer(consumerKeyStr, consumerSecretStr);
			AccessToken accessToken = new AccessToken(accessTokenStr,
					accessTokenSecretStr);

			twitter.setOAuthAccessToken(accessToken);

			twitter.updateStatus("Post using Twitter4J");

			System.out.println("Successfully updated the status in Twitter.");
		} catch (TwitterException te) {
			te.printStackTrace();
		}
	}
 
开发者ID:sshubhadeep,项目名称:TwitterPostUsingTwitterAPI,代码行数:19,代码来源:TwitterPost.java

示例4: configure

import twitter4j.auth.AccessToken; //导入依赖的package包/类
@Override
public void configure(Context context) {
  String consumerKey = context.getString("consumerKey");
  String consumerSecret = context.getString("consumerSecret");
  String accessToken = context.getString("accessToken");
  String accessTokenSecret = context.getString("accessTokenSecret");

  twitterStream = new TwitterStreamFactory().getInstance();
  twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
  twitterStream.setOAuthAccessToken(new AccessToken(accessToken,
                                                    accessTokenSecret));
  twitterStream.addListener(this);
  avroSchema = createAvroSchema();
  dataFileWriter = new DataFileWriter<GenericRecord>(
      new GenericDatumWriter<GenericRecord>(avroSchema));

  maxBatchSize = context.getInteger("maxBatchSize", maxBatchSize);
  maxBatchDurationMillis = context.getInteger("maxBatchDurationMillis",
                                              maxBatchDurationMillis);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TwitterSource.java

示例5: add

import twitter4j.auth.AccessToken; //导入依赖的package包/类
public Observable<Account> add(final AccessToken accessToken) {
    ContentValues values = new ContentValues();

    values.put(AccountContract.TOKEN, accessToken.getToken());
    values.put(AccountContract.TOKEN_SECRET, accessToken.getTokenSecret());
    values.put(AccountContract.SCREEN_NAME, accessToken.getScreenName());
    values.put(AccountContract.USER_ID, accessToken.getUserId());

    return mSqlBriteContentProvider
            .insert(AccountContract.CONTENT_URI, values)
            .flatMap(new Func1<Uri, Observable<SqlBriteContentProvider.Query>>() {
                @Override
                public Observable<SqlBriteContentProvider.Query> call(Uri uri) {
                    return mSqlBriteContentProvider
                            .query(uri, AccountContract.PROJECTION,
                                    null, null, null, false);
                }
            })
            .map(MapFunctions.ACCOUNT)
            .take(1);
}
 
开发者ID:mecid,项目名称:robird-reborn,代码行数:22,代码来源:AccountModel.java

示例6: registerPinCode

import twitter4j.auth.AccessToken; //导入依赖的package包/类
private void registerPinCode(final RequestToken requestToken) {
    if (this.pinIsValid) {
        final Optional<AccessToken> success = this.twitterHandler.registerAccessToken(
                requestToken,
                this.pinCodeField.getText()
        );
        if (success.isPresent()) {
            final AccessToken token = success.get();
            this.loginButton.setVisible(false);
            this.loginLabel.setText(
                    String.format(
                            "Successfully logged in account @%s!",
                            token.getScreenName())
            );
        } else {
            ExceptionHandler.displayExceptionPane(
                    "Authentication Error",
                    "Could not authenticate you!",
                    new Exception("No token could be used.")
            );
        }
        this.stageManager.getSingle(Views.LOGIN_VIEW).peek(Stages::scheduleHiding);
    }
}
 
开发者ID:Tristan971,项目名称:Lyrebird,代码行数:25,代码来源:LoginViewController.java

示例7: doInBackground

import twitter4j.auth.AccessToken; //导入依赖的package包/类
@Override
protected AccessToken doInBackground(String... codes) {
    AccessToken accessToken = null;
    if (codes != null && codes.length > 0) {
        String code = codes[0];
        TwitterClient twitterClient = TwitterClient.instance();
        try {
            accessToken = twitterClient.getAcccessToken(twitterClient.getRequestToken(), code);
        } catch (TwitterException e) {
            e.printStackTrace();
        }
        twitterClient.authenticateUser(accessToken.getToken(), accessToken.getTokenSecret());
    }

    return accessToken;
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:17,代码来源:TwitterPreferencesFragment.java

示例8: getTwitter

import twitter4j.auth.AccessToken; //导入依赖的package包/类
public Twitter getTwitter() throws TwitterException, IOException 
{
   	ConfigurationBuilder cb = new ConfigurationBuilder();
   	
   	cb.setDebugEnabled(true)
   	  .setOAuthConsumerKey(CONSUMER_KEY)
   	  .setOAuthConsumerSecret(CONSUMER_SECRET)
   	  .setOAuthAccessToken(ACCESS_TOKEN)
   	  .setOAuthAccessTokenSecret(ACCESS_SECRET);
   	
   	TwitterFactory tf = new TwitterFactory(cb.build());
   	Twitter twitter = tf.getInstance();
   	
   	twitter.setOAuthAccessToken(new AccessToken(ACCESS_TOKEN, ACCESS_SECRET));

   	return twitter;
}
 
开发者ID:prosecconetwork,项目名称:The-NOC-List,代码行数:18,代码来源:TweetSearcher.java

示例9: getTwitter

import twitter4j.auth.AccessToken; //导入依赖的package包/类
public Twitter getTwitter() throws TwitterException, IOException 
{
   	ConfigurationBuilder cb = new ConfigurationBuilder();
   	
   	cb.setDebugEnabled(true)
   	  .setOAuthConsumerKey(CONSUMER_KEY)
   	  .setOAuthConsumerSecret(CONSUMER_KEY_SECRET);
   	
   	TwitterFactory tf = new TwitterFactory(cb.build());
   	Twitter twitter = tf.getInstance();
   	
   	twitter.setOAuthAccessToken(new AccessToken(ACCESS_TOKEN, 
   												ACCESS_TOKEN_SECRET));

   	return twitter;
}
 
开发者ID:prosecconetwork,项目名称:The-NOC-List,代码行数:17,代码来源:TweetLaunchpad.java

示例10: checkID

import twitter4j.auth.AccessToken; //导入依赖的package包/类
private static void checkID() throws TwitterException {
	twitter = TwitterFactory.getSingleton();
	twitter.setOAuthConsumer("", "");

	requestToken = twitter.getOAuthRequestToken();
	if(Storage.getData(Connection.TOKEN) == null) {
		Ressources.frame.setPanel(new ConnectionPanel(Text.PIN));
		//Open web browser to access PIN code
		new Thread() {
			@Override
			public void run() {
				if(!Infonet.open(requestToken.getAuthorizationURL(), true)) {
					JOptionPane.showMessageDialog(null, Storage.tra("urlError"), Storage.tra("error"), JOptionPane.ERROR_MESSAGE);
				}
			}
		}.start();

	} else {
		accessToken = new AccessToken(Storage.getData(Connection.TOKEN), Storage.getData(Connection.TOKEN_SECRET));
		Main.connect();
	}
}
 
开发者ID:Shadorc,项目名称:Twitter-Stalker-V.2,代码行数:23,代码来源:Main.java

示例11: connect

import twitter4j.auth.AccessToken; //导入依赖的package包/类
/**
 * Authenticates when there is no twitter instance or authorization.
 * If the access token had already been configured it catches the exception, logs
 * and continue with the flow.
 *
 * @throws Exception
 */
private void connect() throws Exception {
    log.info("Authenticate Tweet Harvester.");

    if (twitter != null && twitter.getAuthorization().isEnabled()) {
        log.warning("Already connected to twitter.");
        return;
    }

    try {
        twitter = TwitterFactory.getSingleton();
        AccessToken accessToken = new AccessToken(oauthAccessToken, oauthAccessTokenSecret);
        twitter.setOAuthConsumer(consumerKey, consumerSecret);
        twitter.setOAuthAccessToken(accessToken);
        log.info("Tweet Harvester authenticated with success.");
    } catch (IllegalStateException e) {
        log.error("Something went wrong or Already authenticated: " + e.getMessage());
    }
}
 
开发者ID:fforbeck,项目名称:twitter-analyst,代码行数:26,代码来源:TweetHarvester.java

示例12: saveVariable

import twitter4j.auth.AccessToken; //导入依赖的package包/类
@Override
public boolean saveVariable(String jsonString) {
	if(jsonString.isEmpty() || jsonString == null){ throw new IllegalArgumentException(); }
	JsonObject source = jm.createJsonObject(jsonString);
	if(!source.has("WhiteEggPlayer")){ return false; }
	JsonObject json = source.getAsJsonObject("WhiteEggPlayer");
	JsonObject player = json.getAsJsonObject("player");
	if(json.get("twitter").isJsonObject()){
		JsonObject tw = json.getAsJsonObject("twitter");
		AccessToken token = new AccessToken(tw.get("accesstoken").getAsString(), tw.get("accesstokensecret").getAsString());
		this.getTwitterManager().setAccessToken(token);
	}
	this.setRank(player);
	this.setToggle(player);
	AltAccount.parser(player.toString());
	return true;
}
 
开发者ID:niwaniwa,项目名称:WhiteEggCore,代码行数:18,代码来源:WhiteEggPlayer.java

示例13: start

import twitter4j.auth.AccessToken; //导入依赖的package包/类
private static void start() {
	if (!Twitter.isEnabled) {
		return;
	}
	
	Twitter.client = createClient();
	
	AccessToken accessToken = getAccessToken();
	if (accessToken != null) {
		Twitter.client.setOAuthAccessToken(accessToken);
		logger.info("TwitterAction has been successfully authenticated > awaiting your Tweets!");
	} else {
		logger.info("Twitter authentication failed. Please use OSGi "
			+ "console to restart the org.openhab.io.net-Bundle and re-initiate the authorization process!");
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:17,代码来源:TwitterActionService.java

示例14: doGet

import twitter4j.auth.AccessToken; //导入依赖的package包/类
/**
 * This method handles the Twitter OAuth callback and sets the twtoken cookie.
 *
 * @param req  the http request
 * @param resp the http response
 * @throws ServletException if an error occurred during access
 * @throws IOException      if an error occurred during access
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (req.getParameter("denied") == null) {
        Twitter twitter = (Twitter) req.getSession().getAttribute("twitter");
        RequestToken requestToken = (RequestToken) req.getSession().getAttribute("requestToken");
        String verifier = req.getParameter("oauth_verifier");
        try {
            AccessToken token = twitter.getOAuthAccessToken(requestToken, verifier);
            req.getSession().removeAttribute("requestToken");
            Cookie tokenCookie = new Cookie("twtoken", Base64.getEncoder().encodeToString(
                    (token.getToken() + " - " + token.getTokenSecret()).getBytes()));
            tokenCookie.setMaxAge(-1);
            tokenCookie.setHttpOnly(true);
            resp.addCookie(tokenCookie);

        } catch (TwitterException e) {
            // Redirect to landing page
        }
    }
    resp.sendRedirect(Constants.TWITTER);
}
 
开发者ID:slauber,项目名称:Crawcial,代码行数:30,代码来源:TwAuth.java

示例15: signinCallback

import twitter4j.auth.AccessToken; //导入依赖的package包/类
@RequestMapping(value = "/signin/callback", method = RequestMethod.GET)
public RedirectView signinCallback(@RequestParam("oauth_verifier") final String verifier,
        final HttpServletRequest request) throws WTFDYUMException {
    final RequestToken requestToken = (RequestToken) request.getSession().getAttribute(SESSION_REQUEST_TOKEN);
    request.getSession().removeAttribute(SESSION_REQUEST_TOKEN);

    final AccessToken accessToken = twitterService.completeSignin(requestToken, verifier);

    if (principalService.get(accessToken.getUserId()) == null) {
        userService.addEvent(accessToken.getUserId(), new Event(EventType.REGISTRATION, null));
    }

    final Principal user = new Principal(accessToken.getUserId(), accessToken.getToken(), accessToken.getTokenSecret());
    principalService.saveUpdate(user);
    authenticationService.authenticate(user);

    return new RedirectView("/user", true);
}
 
开发者ID:jchampemont,项目名称:WTFDYUM,代码行数:19,代码来源:MainController.java


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