use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class LoginMethodHandler method getUserIDFromSignedRequest.
private static String getUserIDFromSignedRequest(String signedRequest) throws FacebookException {
if (signedRequest == null || signedRequest.isEmpty()) {
throw new FacebookException("Authorization response does not contain the signed_request");
}
try {
String[] signatureAndPayload = signedRequest.split("\\.");
if (signatureAndPayload.length == 2) {
byte[] data = Base64.decode(signatureAndPayload[1], Base64.DEFAULT);
String dataStr = new String(data, "UTF-8");
JSONObject jsonObject = new JSONObject(dataStr);
return jsonObject.getString("user_id");
}
} catch (UnsupportedEncodingException ex) {
} catch (JSONException ex) {
}
throw new FacebookException("Failed to retrieve user_id from signed_request");
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class WebViewLoginMethodHandler method tryAuthorize.
@Override
boolean tryAuthorize(final LoginClient.Request request) {
Bundle parameters = getParameters(request);
WebDialog.OnCompleteListener listener = new WebDialog.OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
onWebDialogComplete(request, values, error);
}
};
e2e = LoginClient.getE2E();
addLoggingExtra(ServerProtocol.DIALOG_PARAM_E2E, e2e);
FragmentActivity fragmentActivity = loginClient.getActivity();
WebDialog.Builder builder = new AuthDialogBuilder(fragmentActivity, request.getApplicationId(), parameters).setE2E(e2e).setIsRerequest(request.isRerequest()).setOnCompleteListener(listener);
loginDialog = builder.build();
FacebookDialogFragment dialogFragment = new FacebookDialogFragment();
dialogFragment.setRetainInstance(true);
dialogFragment.setDialog(loginDialog);
dialogFragment.show(fragmentActivity.getSupportFragmentManager(), FacebookDialogFragment.TAG);
return true;
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class LoginManager method startLogin.
private void startLogin(StartActivityDelegate startActivityDelegate, LoginClient.Request request) throws FacebookException {
logStartLogin(startActivityDelegate.getActivityContext(), request);
// Make sure the static handler for login is registered if there isn't an explicit callback
CallbackManagerImpl.registerStaticCallback(CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode(), new CallbackManagerImpl.Callback() {
@Override
public boolean onActivityResult(int resultCode, Intent data) {
return LoginManager.this.onActivityResult(resultCode, data);
}
});
boolean started = tryFacebookActivity(startActivityDelegate, request);
if (!started) {
FacebookException exception = new FacebookException("Log in attempt failed: FacebookActivity could not be started." + " Please make sure you added FacebookActivity to the AndroidManifest.");
boolean wasLoginActivityTried = false;
logCompleteLogin(startActivityDelegate.getActivityContext(), LoginClient.Result.Code.ERROR, null, exception, wasLoginActivityTried, request);
throw exception;
}
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class Utility method getStringPropertyAsJSON.
// Returns either a JSONObject or JSONArray representation of the 'key' property of
// 'jsonObject'.
public static Object getStringPropertyAsJSON(JSONObject jsonObject, String key, String nonJSONPropertyKey) throws JSONException {
Object value = jsonObject.opt(key);
if (value != null && value instanceof String) {
JSONTokener tokener = new JSONTokener((String) value);
value = tokener.nextValue();
}
if (value != null && !(value instanceof JSONObject || value instanceof JSONArray)) {
if (nonJSONPropertyKey != null) {
// Facebook sometimes gives us back a non-JSON value such as
// literal "true" or "false" as a result.
// If we got something like that, we present it to the caller as a JSONObject
// with a single property. We only do this if the caller wants that behavior.
jsonObject = new JSONObject();
jsonObject.putOpt(nonJSONPropertyKey, value);
return jsonObject;
} else {
throw new FacebookException("Got an unexpected non-JSON object.");
}
}
return value;
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class SplashFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.splash, container, false);
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Toast.makeText(getActivity(), "Login successful", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(getActivity(), "Login canceled", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(getActivity(), "Login error", Toast.LENGTH_SHORT).show();
}
});
skipLoginButton = (TextView) view.findViewById(R.id.skip_login_button);
skipLoginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (skipLoginCallback != null) {
skipLoginCallback.onSkipLoginPressed();
}
}
});
return view;
}
Aggregations