Example usage for twitter4j.auth AccessToken getScreenName

List of usage examples for twitter4j.auth AccessToken getScreenName

Introduction

In this page you can find the example usage for twitter4j.auth AccessToken getScreenName.

Prototype


public String getScreenName() 

Source Link

Usage

From source file:net.nokok.twitduke.core.account.AccountManagerImpl.java

License:Open Source License

@Override
public void removeAccount(AccessToken accessToken) {
    File accountDir = DirectoryHelper.getAccountDirectory(accessToken.getScreenName());
    accountDir.delete();//  ww w .ja va 2 s  .c o  m
}

From source file:net.nokok.twitduke.core.io.AccessTokenPropertyWriter.java

License:Open Source License

@Override
public void write(AccessToken accessToken) {
    Properties properties = new Properties();
    properties.put(PropertyKey.TOKEN, accessToken.getToken());
    properties.put(PropertyKey.TOKEN_SECRET, accessToken.getTokenSecret());
    properties.put(PropertyKey.USER_ID, String.valueOf(accessToken.getUserId()));
    properties.put(PropertyKey.SCREEN_NAME, accessToken.getScreenName());
    try (java.io.Writer writer = (propertyWriter == null) ? new FileWriter(ACCESS_TOKEN) : propertyWriter) {
        properties.store(writer, null);//from  www.j  a  va  2s.  c om
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}

From source file:net.nokok.twitduke.core.type.AccessTokenProperty.java

License:Open Source License

/**
 * ??????/*from  w  w w  .  j  a  v  a2  s  .com*/
 *
 * @param accessToken
 */
public AccessTokenProperty(AccessToken accessToken) {
    this.accessToken = accessToken;
    properties = new Properties();
    properties.put(TOKEN_KEY, accessToken.getToken());
    properties.put(TOKEN_SECRET_KEY, accessToken.getTokenSecret());
    properties.put(SCREEN_NAME_KEY, Optional.ofNullable(accessToken.getScreenName()).orElse(""));
    properties.put(USER_ID_KEY, String.valueOf(accessToken.getUserId()));
}

From source file:net.nokok.twitduke.core.view.tweetcell.TweetPanelFactoryImpl.java

License:Open Source License

/**
 * ???????????//from ww w .  java2 s. c om
 *
 * @param status      ?
 * @param accessToken 
 *
 */
public TweetPanelFactoryImpl(Status status, AccessToken accessToken) {
    this.status = status;
    this.accessToken = accessToken;
    retweetedStatus = Optional.ofNullable(status.getRetweetedStatus());
    //???RetweeteeStatus?????????status?
    activeStatus = retweetedStatus.orElseGet(() -> status);
    twitter = TAsyncTwitterFactory.newInstance(accessToken);
    this.screenName = accessToken.getScreenName();
}

From source file:org.addhen.smssync.presentation.view.ui.activity.OauthActivity.java

License:Open Source License

@Override
public void onSuccess(TwitterOAuthView view, AccessToken accessToken) {
    TwitterAuthToken authToken = new TwitterAuthToken(accessToken.getToken(), accessToken.getTokenSecret());
    // Persist user session so we can perform actions on protected resources
    App.getTwitterInstance().getSessionManager().setActiveSession(
            new TwitterSession(authToken, accessToken.getUserId(), accessToken.getScreenName()));
    finish();/*w ww  .  j  a  va2s  .  c  om*/
}

From source file:org.encuestame.business.service.AbstractBaseService.java

License:Apache License

/**
 * Get Access Token./*from  www  . ja  v a  2 s. c om*/
 * @param token
 * @param tokenSecret
 * @param pin
 * @return
 * @throws TwitterException
 */
@SuppressWarnings("unused")
private AccessToken getAccessToken(final Twitter twitter, final String token, final String tokenSecret)
        throws TwitterException {

    final AccessToken accessToken = twitter.getOAuthAccessToken(token, tokenSecret);
    log.info(String.format("Auth Token {%s Token Secret {%s ", accessToken.getToken(),
            accessToken.getTokenSecret()));
    twitter.setOAuthAccessToken(accessToken);
    if (accessToken != null) {
        log.info(String.format("Got access token for user %s", accessToken.getScreenName()));
    }
    return accessToken;
}

From source file:org.exoplatform.extensions.twitter.TwitterPortlet.java

License:Open Source License

@Override
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String action = request.getParameter("action");
    if (action != null && action.equals("save")) {
        String pin = request.getParameter("pin");
        // get the object from the session
        RequestToken requestToken = (RequestToken) request.getPortletSession()
                .getAttribute(SESSION_OAUTH_TOKEN);
        TwitterService twitterService = (TwitterService) ExoContainerContext.getCurrentContainer()
                .getComponentInstanceOfType(TwitterService.class);
        AccessToken accessToken = null;
        try {/*from   w w  w .j  a  v  a2s.c  o  m*/
            accessToken = twitterService.getTwitter().getOAuthAccessToken(requestToken, pin);
        } catch (TwitterException ex) {
            Logger.getLogger(TwitterPortlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        twitterService.saveUserPreferences(request.getRemoteUser(), accessToken.getScreenName(),
                accessToken.getToken(), accessToken.getTokenSecret());
    } else if (action != null && action.equals("revoke")) {
        TwitterService twitterService = (TwitterService) ExoContainerContext.getCurrentContainer()
                .getComponentInstanceOfType(TwitterService.class);
        twitterService.removeUserPreferences(request.getRemoteUser());
    }

}

From source file:org.fenixedu.bennu.social.ui.service.TwitterService.java

License:Open Source License

@Atomic(mode = Atomic.TxMode.WRITE)
public void parseResponse(TwitterUser twitterUser, AccessToken oAuthAccessToken)
        throws AccessTokenNotProvidedException {

    String token = oAuthAccessToken.getToken();
    String tokenSecret = oAuthAccessToken.getTokenSecret();
    String screenName = oAuthAccessToken.getScreenName();

    LOGGER.info("Access token request answer from Twitter: Token=" + token + " and TokenSecret=" + tokenSecret
            + " and ScreenName=" + screenName);

    if (token == null) {
        LOGGER.error("Access token has not been returned by Twitter API");
        throw new AccessTokenNotProvidedException(null);
    }//  w  w  w.  j av  a  2s . co m

    twitterUser.setAccessToken(token);
    twitterUser.setTokenSecret(tokenSecret);
    twitterUser.setScreenName(screenName);
}

From source file:org.sush.twitterstream.MyTwitterStream.java

License:Apache License

private void saveAccessToken(AccessToken accessToken) throws IOException {
    String userName = accessToken.getScreenName();
    File file = new File(USER_ACCESS_DIR + userName);
    if (file.createNewFile()) {
        Properties prop = new Properties();
        prop.setProperty("oauth.consumerKey", accessToken.getToken());
        prop.setProperty("oauth.consumerSecret", accessToken.getTokenSecret());
        OutputStream os = new FileOutputStream(file);
        prop.store(os, "access token for the user ::" + userName);
    }/* www.ja va 2s  .  c  o  m*/
}

From source file:ua.group06.presentation.UserLoginTwitter.java

/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request//from w w w  . java  2  s  .c  o m
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Twitter twitter = twitterauth.getTwitter();
    RequestToken requestToken = twitterauth.getRequestToken();
    //RequestToken requestToken = (RequestToken) request.getSession().getAttribute("requestToken");
    String verifier = request.getParameter("oauth_verifier");
    System.err.println(twitter + " " + requestToken + " " + verifier);
    try {
        AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
        System.err.println(accessToken.getScreenName());
        User twitterUser = twitter.showUser(accessToken.getUserId());
        String fullName = twitterUser.getName();
        String fName = "";
        String lName = "";
        String[] names = fullName.split(" ");
        if (names.length == 1) {
            fName = names[0];
        } else if (names.length >= 2) {
            fName = names[0];
            lName = names[names.length - 1];
        }
        ExternalUser user = userService.authenticateOrCreate(accessToken.getScreenName(), "", fName, lName);

        if (user != null) {
            HttpSession session = request.getSession();
            session.setAttribute("user", user);
        }
        //request.getSession().removeAttribute("requestToken");
    } catch (TwitterException e) {
        throw new ServletException(e);
    }
    response.sendRedirect("homepage");
}