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


Java RequestToken类代码示例

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


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

示例1: getTwitterOAuthTokenAndLogin

import twitter4j.auth.RequestToken; //导入依赖的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.RequestToken; //导入依赖的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: registerPinCode

import twitter4j.auth.RequestToken; //导入依赖的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

示例4: connectToTwitter

import twitter4j.auth.RequestToken; //导入依赖的package包/类
private void connectToTwitter() {
    try {
        RequestToken requestToken = twitter.getOAuthRequestToken();
        LoginController.showAndWait(requestToken.getAuthorizationURL(),
                e -> ((String) e.executeScript("document.documentElement.outerHTML"))
                        .contains("You've granted access to"),
                e -> {
                    // TODO: xslt?
                    final String html = "<kbd aria-labelledby=\"code-desc\"><code>";

                    String body = (String) e.executeScript("document.documentElement.outerHTML");
                    final int start = body.indexOf(html) + html.length();
                    String code = body.substring(start, start + 7);
                    saveTwitterAuthentication(requestToken, code);
                    showConfigurationUI();
                });
    } catch (TwitterException ex) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:21,代码来源:TwitterPreferencesController.java

示例5: twitterAuth

import twitter4j.auth.RequestToken; //导入依赖的package包/类
@RequestMapping("/twitter")
public ResponseEntity twitterAuth(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "email", required = false) String email) {
    Twitter twitter = TwitterFactory.getSingleton();

    try {
        RequestToken token = twitter.getOAuthRequestToken(Reference.rootURL + "/v1/oauth/twitter_callback");
        request.getSession().setAttribute("requestToken", token);
        request.getSession().setAttribute("twitter", twitter);
        request.getSession().setAttribute("email", email);
        response.sendRedirect("https://api.twitter.com/oauth/authenticate?oauth_token=" + token.getToken());

        return null;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:19,代码来源:OAuthController.java

示例6: twitterCallback

import twitter4j.auth.RequestToken; //导入依赖的package包/类
@RequestMapping("/twitter_callback")
public ResponseEntity twitterCallback(HttpServletRequest request, HttpServletResponse response, @RequestParam("oauth_token") String token, @RequestParam("oauth_verifier") String verifier) throws TwitterException {
    Twitter twitter = TwitterFactory.getSingleton();

    twitter.getOAuthAccessToken((RequestToken) request.getSession().getAttribute("requestToken"), verifier);

    User twitterUser = twitter.showUser(twitter.getId());
    com.bezman.model.User user = TwitterProvider.userForTwitterUser(twitterUser);
    twitter.setOAuthAccessToken(null);
    com.bezman.model.User queryUser = userService.userForProviderAndProviderID(user.getProvider(), user.getProviderID());

    if (queryUser == null) {
        userService.createConnectedAccountFromPrimaryAccount(user);
    } else {
        user.setId(queryUser.getId());
    }

    this.authService.loginUser(user);
    this.httpService.sendRedirect("/");

    return null;
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:23,代码来源:OAuthController.java

示例7: twitterCallback

import twitter4j.auth.RequestToken; //导入依赖的package包/类
@RequestMapping("/twitter_callback")
@PreAuthorization(minRole = com.bezman.model.User.Role.PENDING)
public ResponseEntity twitterCallback(HttpServletRequest request, @AuthedUser User currentUser, @RequestParam("oauth_token") String token, @RequestParam("oauth_verifier") String verifier) throws TwitterException, IOException {
    Twitter twitter = (Twitter) request.getSession().getAttribute("twitter");
    twitter.getOAuthAccessToken((RequestToken) request.getSession().getAttribute("requestToken"), verifier);

    twitter4j.User twitterUser = twitter.showUser(twitter.getId());
    twitter.setOAuthAccessToken(null);

    com.bezman.model.User connectedUser = TwitterProvider.userForTwitterUser(twitterUser);
    String cutUsername = connectedUser.getUsername().substring(0, connectedUser.getUsername().length() - 4);

    this.connectedAccountService.connectProviderToUser(currentUser, cutUsername, connectedUser.getProvider(), connectedUser.getProviderID());

    this.httpService.sendRedirect("/settings/connections/");

    return null;
}
 
开发者ID:DevWars,项目名称:devwars.tv,代码行数:19,代码来源:UserConnectionController.java

示例8: doGet

import twitter4j.auth.RequestToken; //导入依赖的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

示例9: doPost

import twitter4j.auth.RequestToken; //导入依赖的package包/类
/**
 * This method checks for the required configuration and controls the Twitter login process.
 *
 * @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 doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    loadProperties(req);
    if (CONSUMERKEY == null || CONSUMERKEY.equals("") || CONSUMERSECRET == null || CONSUMERSECRET.equals("")) {
        resp.sendRedirect(Constants.CONFIGURATION + "&e=" + Constants.TWITTER_ERROR);
    } else {
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(CONSUMERKEY, CONSUMERSECRET);
        req.getSession().setAttribute("twitter", twitter);
        try {
            StringBuilder callbackURL = new StringBuilder(req.getRequestURL());
            int index = callbackURL.lastIndexOf("/");
            callbackURL.replace(index, callbackURL.length(), "").append("/twauth");

            RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString());
            req.getSession().setAttribute("requestToken", requestToken);
            resp.sendRedirect(requestToken.getAuthenticationURL());

        } catch (TwitterException e) {
            resp.sendRedirect(Constants.CONFIGURATION + "&e=" + Constants.TWITTER_ERROR);
        }
    }
}
 
开发者ID:slauber,项目名称:Crawcial,代码行数:32,代码来源:TwAuth.java

示例10: signin

import twitter4j.auth.RequestToken; //导入依赖的package包/类
@RequestMapping(value = "/signin", method = RequestMethod.GET)
public RedirectView signin(final HttpServletRequest request) throws WTFDYUMException {
    if (authenticationService.isAuthenticated()) {
        return new RedirectView("/user", true);
    }

    if (maxMembers > 0 && principalService.countMembers() >= maxMembers) {
        throw new WTFDYUMException(WTFDYUMExceptionType.MEMBER_LIMIT_EXCEEDED);
    }

    final RequestToken requestToken = twitterService.signin("/signin/callback");

    request.getSession().setAttribute(SESSION_REQUEST_TOKEN, requestToken);

    return new RedirectView(requestToken.getAuthenticationURL());
}
 
开发者ID:jchampemont,项目名称:WTFDYUM,代码行数:17,代码来源:MainController.java

示例11: signinCallback

import twitter4j.auth.RequestToken; //导入依赖的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

示例12: afterSuccesfullAuthentication

import twitter4j.auth.RequestToken; //导入依赖的package包/类
public String afterSuccesfullAuthentication(HttpServletRequest request) {
    Twitter twitter = new TwitterFactory().getInstance();
    RequestToken token = (RequestToken) request.getSession().getAttribute("requestToken");
    String verifier = request.getParameter("oauth_verifier");
    twitter.setOAuthConsumer(client_id, client_secret);
    try {
         AccessToken accessToken = twitter.getOAuthAccessToken(token, verifier);
        User user = twitter.verifyCredentials();
        AccountJDO account = AccountManager.addAccount(""+user.getId(), AccountJDO.TWITTERCLIENT, "",
                "", "", user.getName(),
                user.getProfileImageURL(),false);
        UserLoggedInManager.submitOauthUser(account.getUniqueId(), accessToken.getToken());
        return accessToken.getToken();
    } catch (TwitterException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
    }
    return null;
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:19,代码来源:OauthTwitterWorker.java

示例13: onCreateLoader

import twitter4j.auth.RequestToken; //导入依赖的package包/类
@Override
public Loader<RequestToken> onCreateLoader(int id, Bundle args) {
	// show ProgressDialog
	mProgressDialog = new ProgressDialog(mContext);
	mProgressDialog.setTitle(R.string.dialog_title_text);
	mProgressDialog.setMessage(mContext
			.getString(R.string.dialog_message_text));
	mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
	mProgressDialog.setCancelable(false);
	mProgressDialog.show();

	// run AsyncTaskLoader
	Loader<RequestToken> loader = new TwitterOAuthRequestTokenLoader(
			mContext, mTwitter);
	loader.startLoading();
	return loader;
}
 
开发者ID:rsato,项目名称:android-sample-twitter4j-auth,代码行数:18,代码来源:TwitterOAuthRequestTokenCallbacks.java

示例14: onClick

import twitter4j.auth.RequestToken; //导入依赖的package包/类
@Override
public void onClick(View v) {
	switch (v.getId()) {
	case R.id.buttonAuth:
		mTwitter = new TwitterFactory().getInstance();
		mTwitter.setOAuthConsumer(getString(R.string.twitter_consumer_key),
				getString(R.string.twitter_consumer_key_secret));
		mTwitter.setOAuthAccessToken(null);
		LoaderManager.LoaderCallbacks<RequestToken> requestTokenCallbacks = new TwitterOAuthRequestTokenCallbacks(
				this, mTwitter);
		getSupportLoaderManager()
				.initLoader(0, null, requestTokenCallbacks);
		break;
	case R.id.buttonSendPin:
		EditText editTextPin = (EditText) findViewById(R.id.editTextPin);
		if (editTextPin.getText().length() > 0 && mTwitter != null) {
			LoaderManager.LoaderCallbacks<AccessToken> accessTokenCallbacks = new TwitterOAuthAccessTokenCallbacks(
					this, mTwitter, editTextPin.getText().toString());
			getSupportLoaderManager().initLoader(1, null,
					accessTokenCallbacks);
		}
		break;
	default:
		break;
	}
}
 
开发者ID:rsato,项目名称:android-sample-twitter4j-auth,代码行数:27,代码来源:MainActivity.java

示例15: doInBackground

import twitter4j.auth.RequestToken; //导入依赖的package包/类
@Override
protected Boolean doInBackground(Void... params) {
    String consumerKey = mainActivity.getString(R.string.app_consumer_key);
    String consumerSecret = mainActivity.getString(R.string.app_consumer_secret);

    Twitter twitter = TwitterUnit.getTwitterFromInstance();
    twitter.setOAuthConsumer(consumerKey, consumerSecret);

    try {
        String token = sharedPreferences.getString(mainActivity.getString(R.string.sp_request_token), null);
        String tokenSecret = sharedPreferences.getString(mainActivity.getString(R.string.sp_request_token_secret), null);
        RequestToken requestToken = new RequestToken(token, tokenSecret);

        accessToken = twitter.getOAuthAccessToken(requestToken, oAuthVerifier);
        useScreenName = twitter.verifyCredentials().getScreenName();
    } catch (Exception e) {
        return false;
    }

    if (isCancelled()) {
        return false;
    }
    return true;
}
 
开发者ID:mthli,项目名称:Tweetin,代码行数:25,代码来源:GetAccessTokenTask.java


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