use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class AppLinkData method createFromJson.
private static AppLinkData createFromJson(String jsonString) {
if (jsonString == null) {
return null;
}
try {
// Any missing or malformed data will result in a JSONException
JSONObject appLinkArgsJson = new JSONObject(jsonString);
String version = appLinkArgsJson.getString(APPLINK_VERSION_KEY);
JSONObject bridgeArgs = appLinkArgsJson.getJSONObject(APPLINK_BRIDGE_ARGS_KEY);
String method = bridgeArgs.getString(BRIDGE_ARGS_METHOD_KEY);
if (method.equals("applink") && version.equals("2")) {
// We have a new deep link
AppLinkData appLinkData = new AppLinkData();
appLinkData.arguments = appLinkArgsJson.getJSONObject(APPLINK_METHOD_ARGS_KEY);
// first look for the "ref" key in the top level args
if (appLinkData.arguments.has(METHOD_ARGS_REF_KEY)) {
appLinkData.ref = appLinkData.arguments.getString(METHOD_ARGS_REF_KEY);
} else if (appLinkData.arguments.has(ARGUMENTS_REFERER_DATA_KEY)) {
// if it's not in the top level args, it could be in the "referer_data" blob
JSONObject refererData = appLinkData.arguments.getJSONObject(ARGUMENTS_REFERER_DATA_KEY);
if (refererData.has(REFERER_DATA_REF_KEY)) {
appLinkData.ref = refererData.getString(REFERER_DATA_REF_KEY);
}
}
if (appLinkData.arguments.has(METHOD_ARGS_TARGET_URL_KEY)) {
appLinkData.targetUri = Uri.parse(appLinkData.arguments.getString(METHOD_ARGS_TARGET_URL_KEY));
}
if (appLinkData.arguments.has(ARGUMENTS_EXTRAS_KEY)) {
JSONObject extrasData = appLinkData.arguments.getJSONObject(ARGUMENTS_EXTRAS_KEY);
if (extrasData.has(EXTRAS_DEEPLINK_CONTEXT_KEY)) {
JSONObject deeplink_context = extrasData.getJSONObject(EXTRAS_DEEPLINK_CONTEXT_KEY);
if (deeplink_context.has(PROMOTION_CODE_KEY)) {
appLinkData.promotionCode = deeplink_context.getString(PROMOTION_CODE_KEY);
}
}
}
appLinkData.argumentBundle = toBundle(appLinkData.arguments);
return appLinkData;
}
} catch (JSONException e) {
Log.d(TAG, "Unable to parse AppLink JSON", e);
} catch (FacebookException e) {
Log.d(TAG, "Unable to parse AppLink JSON", e);
}
return null;
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class AppLinkData method toBundle.
private static Bundle toBundle(JSONObject node) throws JSONException {
Bundle bundle = new Bundle();
@SuppressWarnings("unchecked") Iterator<String> fields = node.keys();
while (fields.hasNext()) {
String key = fields.next();
Object value;
value = node.get(key);
if (value instanceof JSONObject) {
bundle.putBundle(key, toBundle((JSONObject) value));
} else if (value instanceof JSONArray) {
JSONArray valueArr = (JSONArray) value;
if (valueArr.length() == 0) {
bundle.putStringArray(key, new String[0]);
} else {
Object firstNode = valueArr.get(0);
if (firstNode instanceof JSONObject) {
Bundle[] bundles = new Bundle[valueArr.length()];
for (int i = 0; i < valueArr.length(); i++) {
bundles[i] = toBundle(valueArr.getJSONObject(i));
}
bundle.putParcelableArray(key, bundles);
} else if (firstNode instanceof JSONArray) {
// we don't support nested arrays
throw new FacebookException("Nested arrays are not supported.");
} else {
// just use the string value
String[] arrValues = new String[valueArr.length()];
for (int i = 0; i < valueArr.length(); i++) {
arrValues[i] = valueArr.get(i).toString();
}
bundle.putStringArray(key, arrValues);
}
}
} else {
bundle.putString(key, value.toString());
}
}
return bundle;
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class AppEvent method getJSONObjectForAppEvent.
private static JSONObject getJSONObjectForAppEvent(String contextName, String eventName, Double valueToSum, Bundle parameters, boolean isImplicitlyLogged, @Nullable final UUID currentSessionId) throws FacebookException, JSONException {
validateIdentifier(eventName);
JSONObject eventObject = new JSONObject();
eventObject.put(Constants.EVENT_NAME_EVENT_KEY, eventName);
eventObject.put(Constants.LOG_TIME_APP_EVENT_KEY, System.currentTimeMillis() / 1000);
eventObject.put("_ui", contextName);
if (currentSessionId != null) {
eventObject.put("_session_id", currentSessionId);
}
if (valueToSum != null) {
eventObject.put("_valueToSum", valueToSum.doubleValue());
}
if (isImplicitlyLogged) {
eventObject.put("_implicitlyLogged", "1");
}
String externalAnalyticsUserId = AppEventsLogger.getUserID();
if (externalAnalyticsUserId != null) {
eventObject.put("_app_user_id", externalAnalyticsUserId);
}
if (parameters != null) {
for (String key : parameters.keySet()) {
validateIdentifier(key);
Object value = parameters.get(key);
if (!(value instanceof String) && !(value instanceof Number)) {
throw new FacebookException(String.format("Parameter value '%s' for key '%s' should be a string" + " or a numeric type.", value, key));
}
eventObject.put(key, value.toString());
}
}
if (!isImplicitlyLogged) {
Logger.log(LoggingBehavior.APP_EVENTS, "AppEvents", "Created app event '%s'", eventObject.toString());
}
return eventObject;
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class DialogPresenter method setupAppCallForWebFallbackDialog.
public static void setupAppCallForWebFallbackDialog(AppCall appCall, Bundle parameters, DialogFeature feature) {
Validate.hasFacebookActivity(FacebookSdk.getApplicationContext());
Validate.hasInternetPermissions(FacebookSdk.getApplicationContext());
String featureName = feature.name();
Uri fallbackUrl = getDialogWebFallbackUri(feature);
if (fallbackUrl == null) {
throw new FacebookException("Unable to fetch the Url for the DialogFeature : '" + featureName + "'");
}
// Since we're talking to the server here, let's use the latest version we know about.
// We know we are going to be communicating over a bucketed protocol.
int protocolVersion = NativeProtocol.getLatestKnownVersion();
Bundle webParams = ServerProtocol.getQueryParamsForPlatformActivityIntentWebFallback(appCall.getCallId().toString(), protocolVersion, parameters);
if (webParams == null) {
throw new FacebookException("Unable to fetch the app's key-hash");
}
// Now form the Uri
if (fallbackUrl.isRelative()) {
fallbackUrl = Utility.buildUri(ServerProtocol.getDialogAuthority(), fallbackUrl.toString(), webParams);
} else {
fallbackUrl = Utility.buildUri(fallbackUrl.getAuthority(), fallbackUrl.getPath(), webParams);
}
Bundle intentParameters = new Bundle();
intentParameters.putString(NativeProtocol.WEB_DIALOG_URL, fallbackUrl.toString());
intentParameters.putBoolean(NativeProtocol.WEB_DIALOG_IS_FALLBACK, true);
Intent webDialogIntent = new Intent();
NativeProtocol.setupProtocolRequestIntent(webDialogIntent, appCall.getCallId().toString(), feature.getAction(), NativeProtocol.getLatestKnownVersion(), intentParameters);
webDialogIntent.setClass(FacebookSdk.getApplicationContext(), FacebookActivity.class);
webDialogIntent.setAction(FacebookDialogFragment.TAG);
appCall.setRequestIntent(webDialogIntent);
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class FacebookDialogFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (this.dialog == null) {
final FragmentActivity activity = getActivity();
Intent intent = activity.getIntent();
Bundle params = NativeProtocol.getMethodArgumentsFromIntent(intent);
boolean isWebFallback = params.getBoolean(NativeProtocol.WEB_DIALOG_IS_FALLBACK, false);
WebDialog webDialog;
if (!isWebFallback) {
String actionName = params.getString(NativeProtocol.WEB_DIALOG_ACTION);
Bundle webParams = params.getBundle(NativeProtocol.WEB_DIALOG_PARAMS);
if (Utility.isNullOrEmpty(actionName)) {
Utility.logd(TAG, "Cannot start a WebDialog with an empty/missing 'actionName'");
activity.finish();
return;
}
webDialog = new WebDialog.Builder(activity, actionName, webParams).setOnCompleteListener(new WebDialog.OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
onCompleteWebDialog(values, error);
}
}).build();
} else {
String url = params.getString(NativeProtocol.WEB_DIALOG_URL);
if (Utility.isNullOrEmpty(url)) {
Utility.logd(TAG, "Cannot start a fallback WebDialog with an empty/missing 'url'");
activity.finish();
return;
}
String redirectUrl = String.format("fb%s://bridge/", FacebookSdk.getApplicationId());
webDialog = new FacebookWebFallbackDialog(activity, url, redirectUrl);
webDialog.setOnCompleteListener(new WebDialog.OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
// Error data is nested in the values since this is in the form of a
// Native protocol response
onCompleteWebFallbackDialog(values);
}
});
}
this.dialog = webDialog;
}
}
Aggregations