本文整理匯總了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();
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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());
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}