Search in sources :

Example 11 with Request

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

the class FriendPickerFragment method createRequest.

private Request createRequest(String userID, Set<String> extraFields, Session session) {
    Request request = Request.newGraphPathRequest(session, userID + "/friends", null);
    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[] { ID, NAME };
    fields.addAll(Arrays.asList(requiredFields));
    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }
    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);
    return request;
}
Also used : Bundle(android.os.Bundle) Request(com.facebook.Request)

Example 12 with Request

use of com.facebook.Request 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 13 with Request

use of com.facebook.Request 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

Request (com.facebook.Request)13 Bundle (android.os.Bundle)8 Response (com.facebook.Response)4 Session (com.facebook.Session)4 GraphObject (com.facebook.model.GraphObject)3 GraphUser (com.facebook.model.GraphUser)3 FacebookRequestError (com.facebook.FacebookRequestError)2 GraphUserListCallback (com.facebook.Request.GraphUserListCallback)2 Random (java.util.Random)2 GraphUserCallback (com.facebook.Request.GraphUserCallback)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashSet (java.util.HashSet)1