Search in sources :

Example 51 with FacebookException

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

the class NativeAppLoginMethodHandler method handleResultOk.

private LoginClient.Result handleResultOk(LoginClient.Request request, Intent data) {
    Bundle extras = data.getExtras();
    String error = getError(extras);
    String errorCode = extras.getString("error_code");
    String errorMessage = getErrorMessage(extras);
    String e2e = extras.getString(NativeProtocol.FACEBOOK_PROXY_AUTH_E2E_KEY);
    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }
    if (error == null && errorCode == null && errorMessage == null) {
        try {
            AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(), extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB, request.getApplicationId());
            return LoginClient.Result.createTokenResult(request, token);
        } catch (FacebookException ex) {
            return LoginClient.Result.createErrorResult(request, null, ex.getMessage());
        }
    } else if (ServerProtocol.errorsProxyAuthDisabled.contains(error)) {
        return null;
    } else if (ServerProtocol.errorsUserCanceled.contains(error)) {
        return LoginClient.Result.createCancelResult(request, null);
    } else {
        return LoginClient.Result.createErrorResult(request, error, errorMessage, errorCode);
    }
}
Also used : Bundle(android.os.Bundle) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException)

Example 52 with FacebookException

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

the class WebLoginMethodHandler method onComplete.

protected void onComplete(LoginClient.Request request, Bundle values, FacebookException error) {
    LoginClient.Result outcome;
    e2e = null;
    if (values != null) {
        // Actual e2e we got from the dialog should be used for logging.
        if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) {
            e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E);
        }
        try {
            AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(), values, getTokenSource(), request.getApplicationId());
            outcome = LoginClient.Result.createTokenResult(loginClient.getPendingRequest(), token);
            // Ensure any cookies set by the dialog are saved
            // This is to work around a bug where CookieManager may fail to instantiate if
            // CookieSyncManager has never been created.
            CookieSyncManager syncManager = CookieSyncManager.createInstance(loginClient.getActivity());
            syncManager.sync();
            saveCookieToken(token.getToken());
        } catch (FacebookException ex) {
            outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, ex.getMessage());
        }
    } else {
        if (error instanceof FacebookOperationCanceledException) {
            outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(), "User canceled log in.");
        } else {
            // Something went wrong, don't log a completion event since it will skew timing
            // results.
            e2e = null;
            String errorCode = null;
            String errorMessage = error.getMessage();
            if (error instanceof FacebookServiceException) {
                FacebookRequestError requestError = ((FacebookServiceException) error).getRequestError();
                errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode());
                errorMessage = requestError.toString();
            }
            outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, errorMessage, errorCode);
        }
    }
    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }
    loginClient.completeAndValidate(outcome);
}
Also used : FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) AccessToken(com.facebook.AccessToken) CookieSyncManager(android.webkit.CookieSyncManager) FacebookException(com.facebook.FacebookException) FacebookServiceException(com.facebook.FacebookServiceException) FacebookRequestError(com.facebook.FacebookRequestError)

Example 53 with FacebookException

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

the class LoginManager method onActivityResult.

boolean onActivityResult(int resultCode, Intent data, FacebookCallback<LoginResult> callback) {
    FacebookException exception = null;
    AccessToken newToken = null;
    LoginClient.Result.Code code = LoginClient.Result.Code.ERROR;
    Map<String, String> loggingExtras = null;
    LoginClient.Request originalRequest = null;
    boolean isCanceled = false;
    if (data != null) {
        LoginClient.Result result = data.getParcelableExtra(LoginFragment.RESULT_KEY);
        if (result != null) {
            originalRequest = result.request;
            code = result.code;
            if (resultCode == Activity.RESULT_OK) {
                if (result.code == LoginClient.Result.Code.SUCCESS) {
                    newToken = result.token;
                } else {
                    exception = new FacebookAuthorizationException(result.errorMessage);
                }
            } else if (resultCode == Activity.RESULT_CANCELED) {
                isCanceled = true;
            }
            loggingExtras = result.loggingExtras;
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        isCanceled = true;
        code = LoginClient.Result.Code.CANCEL;
    }
    if (exception == null && newToken == null && !isCanceled) {
        exception = new FacebookException("Unexpected call to LoginManager.onActivityResult");
    }
    boolean wasLoginActivityTried = true;
    //Sadly, there is no way to get activity context at this point.S
    Context context = null;
    logCompleteLogin(context, code, loggingExtras, exception, wasLoginActivityTried, originalRequest);
    finishLogin(newToken, originalRequest, exception, isCanceled, callback);
    return true;
}
Also used : FacebookAuthorizationException(com.facebook.FacebookAuthorizationException) Context(android.content.Context) FacebookException(com.facebook.FacebookException) AccessToken(com.facebook.AccessToken)

Example 54 with FacebookException

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

the class ShareContentValidation method validateOpenGraphValueContainer.

private static void validateOpenGraphValueContainer(ShareOpenGraphValueContainer valueContainer, Validator validator, boolean requireNamespace) {
    Set<String> keySet = valueContainer.keySet();
    for (String key : keySet) {
        validateOpenGraphKey(key, requireNamespace);
        Object o = valueContainer.get(key);
        if (o instanceof List) {
            List list = (List) o;
            for (Object objectInList : list) {
                if (objectInList == null) {
                    throw new FacebookException("Cannot put null objects in Lists in " + "ShareOpenGraphObjects and ShareOpenGraphActions");
                }
                validateOpenGraphValueContainerObject(objectInList, validator);
            }
        } else {
            validateOpenGraphValueContainerObject(o, validator);
        }
    }
}
Also used : FacebookException(com.facebook.FacebookException) ShareOpenGraphObject(com.facebook.share.model.ShareOpenGraphObject) List(java.util.List)

Example 55 with FacebookException

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

the class DeviceAuthDialog method startLogin.

public void startLogin(final LoginClient.Request request) {
    this.mRequest = request;
    final Bundle parameters = new Bundle();
    parameters.putString("scope", TextUtils.join(",", request.getPermissions()));
    String redirectUriString = request.getDeviceRedirectUriString();
    if (redirectUriString != null) {
        parameters.putString("redirect_uri", redirectUriString);
    }
    String accessToken = Validate.hasAppID() + "|" + Validate.hasClientToken();
    parameters.putString(GraphRequest.ACCESS_TOKEN_PARAM, accessToken);
    parameters.putString(DeviceRequestsHelper.DEVICE_INFO_PARAM, DeviceRequestsHelper.getDeviceInfo());
    GraphRequest graphRequest = new GraphRequest(null, DEVICE_LOGIN_ENDPOINT, parameters, HttpMethod.POST, new GraphRequest.Callback() {

        @Override
        public void onCompleted(GraphResponse response) {
            if (isBeingDestroyed) {
                return;
            }
            if (response.getError() != null) {
                onError(response.getError().getException());
                return;
            }
            JSONObject jsonObject = response.getJSONObject();
            RequestState requestState = new RequestState();
            try {
                requestState.setUserCode(jsonObject.getString("user_code"));
                requestState.setRequestCode(jsonObject.getString("code"));
                requestState.setInterval(jsonObject.getLong("interval"));
            } catch (JSONException ex) {
                onError(new FacebookException(ex));
                return;
            }
            setCurrentRequestState(requestState);
        }
    });
    graphRequest.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) Bundle(android.os.Bundle) FacebookException(com.facebook.FacebookException) JSONException(org.json.JSONException)

Aggregations

FacebookException (com.facebook.FacebookException)70 Bundle (android.os.Bundle)24 JSONObject (org.json.JSONObject)24 JSONException (org.json.JSONException)19 Bitmap (android.graphics.Bitmap)13 GraphRequest (com.facebook.GraphRequest)10 JSONArray (org.json.JSONArray)10 Intent (android.content.Intent)9 Uri (android.net.Uri)8 GraphResponse (com.facebook.GraphResponse)8 URISyntaxException (java.net.URISyntaxException)8 AccessToken (com.facebook.AccessToken)7 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)5 FacebookRequestError (com.facebook.FacebookRequestError)5 LoginResult (com.facebook.login.LoginResult)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 InputStreamReader (java.io.InputStreamReader)5 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5