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"));
}
}
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");
}
}
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");
}
}
Aggregations