Example usage for twitter4j AsyncTwitter showUser

List of usage examples for twitter4j AsyncTwitter showUser

Introduction

In this page you can find the example usage for twitter4j AsyncTwitter showUser.

Prototype

void showUser(long userId);

Source Link

Document

Returns extended information of a given user, specified by ID or screen name as per the required id parameter.

Usage

From source file:com.marpies.ane.twitter.functions.GetLoggedInUserFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    mCallbackID = FREObjectUtils.getInt(args[0]);

    User user = TwitterAPI.getLoggedInUser();

    /* Return cached object */
    if (user != null) {
        try {/*from www  .j av  a 2s  . c  o  m*/
            dispatchUser(user);
        } catch (Exception e) {
            e.printStackTrace();
            AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_ERROR,
                    StringUtils.getEventErrorJSON(mCallbackID, e.getMessage()));
        }
    }
    /* Request user info */
    else if (TwitterAPI.hasAccessTokens()) {
        AccessToken accessToken = TwitterAPI.getAccessToken();
        AsyncTwitter twitter = TwitterAPI.getAsyncInstance(accessToken);
        twitter.addListener(this);
        twitter.showUser(accessToken.getUserId());
    }
    /* User not logged in, error */
    else {
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_ERROR,
                StringUtils.getEventErrorJSON(mCallbackID, "User is not logged in."));
    }

    return null;
}

From source file:com.marpies.ane.twitter.functions.GetUserFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    long userID = FREObjectUtils.getDouble(args[0]).longValue();
    String screenName = (args[1] == null) ? null : FREObjectUtils.getString(args[1]);
    mCallbackID = FREObjectUtils.getInt(args[2]);

    AccessToken accessToken = TwitterAPI.getAccessToken();
    AsyncTwitter twitter = TwitterAPI.getAsyncInstance(accessToken);
    twitter.addListener(this);
    if (screenName != null) {
        AIR.log("Getting user info for " + screenName);
        twitter.showUser(screenName);
    } else {//from ww  w . ja v a2 s .com
        AIR.log("Getting user info for userID: " + userID);
        twitter.showUser(userID);
    }

    return null;
}