Search in sources :

Example 1 with GraphUserListCallback

use of com.facebook.Request.GraphUserListCallback in project openkit-android by OpenKit.

the class FacebookUtilities method GetFBFriends.

public static void GetFBFriends(final GetFBFriendsRequestHandler requestHandler) {
    if (OKManager.INSTANCE.getFbFriendsArrayList() != null) {
        OKLog.v("Using cached list of FB friends");
        requestHandler.onSuccess(OKManager.INSTANCE.getFbFriendsArrayList());
        return;
    }
    OKLog.d("Getting list of FB friends");
    Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
        Request friendsRequest = Request.newMyFriendsRequest(session, new GraphUserListCallback() {

            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                FacebookRequestError error = response.getError();
                if (error != null) {
                    OKLog.d("Error getting Facebook friends");
                    requestHandler.onFail(error);
                } else {
                    OKLog.d("Got %d facebook friends", users.size());
                    // Munge the Facebook friends into a JSONArray of friend IDs
                    ArrayList<Long> friendsIDsArrayList = new ArrayList<Long>();
                    for (int x = 0; x < users.size(); x++) {
                        String friendFbID = users.get(x).getId();
                        friendsIDsArrayList.add(Long.parseLong(friendFbID));
                    }
                    OKManager.INSTANCE.setFbFriendsArrayList(friendsIDsArrayList);
                    requestHandler.onSuccess(friendsIDsArrayList);
                }
            }
        });
        friendsRequest.executeAsync();
    } else {
        requestHandler.onFail(new FacebookRequestError(FacebookRequestError.INVALID_ERROR_CODE, "OpenKit", "Facebook session is not open"));
    }
}
Also used : GraphUser(com.facebook.model.GraphUser) GraphUserListCallback(com.facebook.Request.GraphUserListCallback) ArrayList(java.util.ArrayList)

Example 2 with GraphUserListCallback

use of com.facebook.Request.GraphUserListCallback in project openkit-android by OpenKit.

the class ScoreCreator method CreateGlobalScores.

public static void CreateGlobalScores(int aNumScores, int aLeaderboardID, final int maxScoreValue) {
    final int numScores = aNumScores;
    final int leaderboardID = aLeaderboardID;
    OKLog.d("Getting list of FB friends");
    Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
        Request friendsRequest = Request.newMyFriendsRequest(session, new GraphUserListCallback() {

            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                FacebookRequestError error = response.getError();
                if (error != null) {
                    OKLog.d("Error getting Facebook friends");
                //requestHandler.onFail(error);
                } else {
                    OKLog.d("Got %d facebook friends", users.size());
                    Random generator = new Random();
                    for (int x = 0; x < numScores; x++) {
                        int friendIndex = generator.nextInt(users.size());
                        CreateScoreForFBUser(users.get(friendIndex), leaderboardID, x, maxScoreValue);
                    }
                }
            }
        });
        friendsRequest.executeAsync();
    } else {
        OKLog.v("FB session not open");
    }
}
Also used : Response(com.facebook.Response) GraphUser(com.facebook.model.GraphUser) Random(java.util.Random) GraphUserListCallback(com.facebook.Request.GraphUserListCallback) Request(com.facebook.Request) FacebookRequestError(com.facebook.FacebookRequestError) Session(com.facebook.Session)

Example 3 with GraphUserListCallback

use of com.facebook.Request.GraphUserListCallback in project openkit-android by OpenKit.

the class ScoreCreator method CreateFriendsScores.

public static void CreateFriendsScores(int aNumScores, int aLeaderboardID, int maxScoreValue) {
    final int numScores = aNumScores;
    final int leaderboardID = aLeaderboardID;
    OKLog.d("Getting list of FB friends");
    Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
        Request friendsRequest = Request.newMyFriendsRequest(session, new GraphUserListCallback() {

            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                FacebookRequestError error = response.getError();
                if (error != null) {
                    OKLog.d("Error getting Facebook friends");
                } else {
                    OKLog.d("Got %d facebook friends", users.size());
                    Random generator = new Random();
                    for (int x = 0; x < numScores; x++) {
                        int friendIndex = generator.nextInt(users.size());
                        CreateFriendScore(users.get(friendIndex), leaderboardID, x);
                    }
                }
            }
        });
        friendsRequest.executeAsync();
    } else {
        OKLog.v("FB session not open");
    }
}
Also used : Response(com.facebook.Response) GraphUser(com.facebook.model.GraphUser) Random(java.util.Random) GraphUserListCallback(com.facebook.Request.GraphUserListCallback) Request(com.facebook.Request) FacebookRequestError(com.facebook.FacebookRequestError) Session(com.facebook.Session)

Aggregations

GraphUserListCallback (com.facebook.Request.GraphUserListCallback)3 GraphUser (com.facebook.model.GraphUser)3 FacebookRequestError (com.facebook.FacebookRequestError)2 Request (com.facebook.Request)2 Response (com.facebook.Response)2 Session (com.facebook.Session)2 Random (java.util.Random)2 ArrayList (java.util.ArrayList)1