Search in sources :

Example 6 with FacebookRequestError

use of com.facebook.FacebookRequestError in project facebook-android-sdk by facebook.

the class PlacesGraphSDKHelper method provideCurrentPlaceFeedback.

/**
 * Creates and executes a current place feedback request. This request is used to provide
 * feedback on the accuracy of the current place response.
 *
 * @param currentPlaceResult The result of the current place request.
 * @param place The place where the user is (or isn't') located.
 * @param wasHere true to indicate that the user is located at the place, and
 * false to indicate that the user is not located at the place.
 */
public static void provideCurrentPlaceFeedback(final CurrentPlaceResult currentPlaceResult, final Place place, final boolean wasHere) {
    // Creates the builder of the current place feedback request.
    CurrentPlaceFeedbackRequestParams.Builder builder = new CurrentPlaceFeedbackRequestParams.Builder();
    /**
     * Sets the tracking ID, which is used as a correlator to the current place response.
     * The tracking ID is retrieved from the current place response.
     */
    builder.setTracking(currentPlaceResult.getTracking());
    // The place at which the user is (or is not) located.
    String placeId = place.get(Place.ID);
    builder.setPlaceId(placeId);
    // Indicates if the user is or is not at the place.
    builder.setWasHere(wasHere);
    GraphRequest request = PlaceManager.newCurrentPlaceFeedbackRequest(builder.build());
    GraphRequest.Callback callback = new GraphRequest.Callback() {

        @Override
        public void onCompleted(GraphResponse response) {
            boolean success = false;
            FacebookRequestError error = response.getError();
            if (error == null) {
                JSONObject jsonObject = response.getJSONObject();
                success = jsonObject.optBoolean("success");
            } else {
                Log.d(TAG, "response error: " + error);
            }
            Log.d(TAG, "provideCurrentPlaceFeedback: onCompleted: response: success=" + success);
        }
    };
    request.setCallback(callback);
    request.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) CurrentPlaceFeedbackRequestParams(com.facebook.places.model.CurrentPlaceFeedbackRequestParams) FacebookRequestError(com.facebook.FacebookRequestError)

Example 7 with FacebookRequestError

use of com.facebook.FacebookRequestError in project FirebaseUI-Android by firebase.

the class FacebookProvider method onSuccess.

@Override
public void onSuccess(final LoginResult loginResult) {
    GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {

        @Override
        public void onCompleted(JSONObject object, GraphResponse response) {
            FacebookRequestError requestError = response.getError();
            if (requestError != null) {
                Log.e(TAG, "Received Facebook error: " + requestError.getErrorMessage());
                onFailure(new Bundle());
                return;
            }
            if (object == null) {
                Log.w(TAG, "Received null response from Facebook GraphRequest");
                onFailure(new Bundle());
            } else {
                try {
                    String email = object.getString("email");
                    onSuccess(email, loginResult);
                } catch (JSONException e) {
                    Log.e(TAG, "JSON Exception reading from Facebook GraphRequest", e);
                    onFailure(new Bundle());
                }
            }
        }
    });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,email");
    request.setParameters(parameters);
    request.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) Bundle(android.os.Bundle) JSONException(org.json.JSONException) FacebookRequestError(com.facebook.FacebookRequestError)

Example 8 with FacebookRequestError

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

the class OKSocialLeaderboardFragment method getSocialScoresFromOpenKit.

private void getSocialScoresFromOpenKit() {
    if (FacebookUtilities.isFBSessionOpen()) {
        startedSocialRequest();
        FacebookUtilities.GetFBFriends(new GetFBFriendsRequestHandler() {

            @Override
            public void onSuccess(ArrayList<Long> friendsArray) {
                currentLeaderboard.getFacebookFriendsScoresWithFacebookFriends(friendsArray, new OKScoresResponseHandler() {

                    @Override
                    public void onSuccess(List<OKScore> scoresList) {
                        OKLog.v("Got %d social scores!", scoresList.size());
                        addScoresToSocialScoresListAdapater(scoresList);
                        stoppedSocialRequest();
                    }

                    @Override
                    public void onFailure(Throwable e, JSONObject errorResponse) {
                        OKLog.v("Failed to get social scores from OpenKit: " + e);
                        stoppedSocialRequest();
                    }
                });
            }

            @Override
            public void onFail(FacebookRequestError error) {
                OKLog.v("Failed to get Facebook friends");
                stoppedSocialRequest();
            }
        });
    }
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) GetFBFriendsRequestHandler(io.openkit.facebookutils.FacebookUtilities.GetFBFriendsRequestHandler) FacebookRequestError(com.facebook.FacebookRequestError)

Example 9 with FacebookRequestError

use of com.facebook.FacebookRequestError 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 10 with FacebookRequestError

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

FacebookRequestError (com.facebook.FacebookRequestError)20 JSONObject (org.json.JSONObject)10 GraphRequest (com.facebook.GraphRequest)9 JSONException (org.json.JSONException)9 GraphResponse (com.facebook.GraphResponse)8 Bundle (android.os.Bundle)7 FacebookException (com.facebook.FacebookException)6 Uri (android.net.Uri)3 ArrayList (java.util.ArrayList)3 JSONArray (org.json.JSONArray)3 FacebookCallback (com.facebook.FacebookCallback)2 FacebookGraphResponseException (com.facebook.FacebookGraphResponseException)2 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)2 FacebookServiceException (com.facebook.FacebookServiceException)2 Request (com.facebook.Request)2 GraphUserListCallback (com.facebook.Request.GraphUserListCallback)2 Response (com.facebook.Response)2 Session (com.facebook.Session)2 GraphUser (com.facebook.model.GraphUser)2 List (java.util.List)2