Example usage for twitter4j User getEmail

List of usage examples for twitter4j User getEmail

Introduction

In this page you can find the example usage for twitter4j User getEmail.

Prototype

String getEmail();

Source Link

Document

Returns the email of the user, if the app is whitelisted by Twitter

Usage

From source file:org.gameontext.auth.twitter.TwitterCallback.java

License:Apache License

/**
 * Method that performs introspection on an AUTH string, and returns data as
 * a String->String hashmap.//from   www.  j a  v  a 2s  .  c  o  m
 *
 * @param auth
 *            the authstring to query, as built by an auth impl.
 * @return the data from the introspect, in a map.
 * @throws IOException
 *             if anything goes wrong.
 */
public Map<String, String> introspectAuth(String token, String tokensecret) throws IOException {
    Map<String, String> results = new HashMap<String, String>();

    ConfigurationBuilder c = new ConfigurationBuilder();
    c.setOAuthConsumerKey(key).setOAuthConsumerSecret(secret).setOAuthAccessToken(token)
            .setOAuthAccessTokenSecret(tokensecret).setIncludeEmailEnabled(true).setJSONStoreEnabled(true);

    Twitter twitter = new TwitterFactory(c.build()).getInstance();

    try {
        // ask twitter to verify the token & tokensecret from the auth
        // string
        // if invalid, it'll throw a TwitterException
        User verified = twitter.verifyCredentials();

        // if it's valid, lets grab a little more info about the user.
        String name = verified.getName();
        String email = verified.getEmail();

        results.put("valid", "true");
        results.put("id", "twitter:" + twitter.getId());
        results.put("name", name);
        results.put("email", email);

    } catch (TwitterException e) {
        results.put("valid", "false");
    }

    return results;
}

From source file:org.wso2.carbon.identity.authenticator.twitter.TwitterAuthenticator.java

License:Open Source License

public void buildClaims(User user, AuthenticationContext context) {
    AuthenticatedUser authenticatedUserObj;
    authenticatedUserObj = AuthenticatedUser
            .createFederateAuthenticatedUserFromSubjectIdentifier(user.getId() + "");
    authenticatedUserObj.setAuthenticatedSubjectIdentifier(user.getId() + "");

    Map<ClaimMapping, String> claims = new HashMap<ClaimMapping, String>();
    claims.put(ClaimMapping.build(TwitterAuthenticatorConstants.TWITTER_CLAIM_NAME,
            TwitterAuthenticatorConstants.TWITTER_CLAIM_NAME, (String) null, false), user.getName());
    claims.put(ClaimMapping.build(TwitterAuthenticatorConstants.TWITTER_CLAIM_EMAIL,
            TwitterAuthenticatorConstants.TWITTER_CLAIM_EMAIL, (String) null, false), user.getEmail());
    authenticatedUserObj.setUserAttributes(claims);
    context.setSubject(authenticatedUserObj);
}