com.facebook.internal.NativeProtocol Java Examples

The following examples show how to use com.facebook.internal.NativeProtocol. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FacebookDialog.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the results of a dialog activity and calls the appropriate method on the provided Callback.
 *
 * @param context the Context that is handling the activity result
 * @param appCall an PendingCall containing the call ID and original Intent used to launch the dialog
 * @param requestCode the request code for the activity result
 * @param data the result Intent
 * @param callback a callback to call after parsing the results
 *
 * @return true if the activity result was handled, false if not
 */
public static boolean handleActivityResult(Context context, PendingCall appCall, int requestCode, Intent data,
        Callback callback) {
    if (requestCode != appCall.getRequestCode()) {
        return false;
    }

    if (attachmentStore != null) {
        attachmentStore.cleanupAttachmentsForCall(context, appCall.getCallId());
    }

    if (callback != null) {
        if (NativeProtocol.isErrorResult(data)) {
            Exception error = NativeProtocol.getErrorFromResult(data);
            callback.onError(appCall, error, data.getExtras());
        } else {
            callback.onComplete(appCall, data.getExtras());
        }
    }

    return true;
}
 
Example #2
Source File: FacebookDialog.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
private void updateActionAttachmentUrls(List<String> attachmentUrls, boolean isUserGenerated) {
    List<JSONObject> attachments = action.getImage();
    if (attachments == null) {
        attachments = new ArrayList<JSONObject>(attachmentUrls.size());
    }

    for (String url : attachmentUrls) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put(NativeProtocol.IMAGE_URL_KEY, url);
            if (isUserGenerated) {
                jsonObject.put(NativeProtocol.IMAGE_USER_GENERATED_KEY, true);
            }
        } catch (JSONException e) {
            throw new FacebookException("Unable to attach images", e);
        }
        attachments.add(jsonObject);
    }
    action.setImage(attachments);
}
 
Example #3
Source File: UiLifecycleHelper.java    From android-skeleton-project with MIT License 6 votes vote down vote up
private void cancelPendingAppCall(FacebookDialog.Callback facebookDialogCallback) {
    if (facebookDialogCallback != null) {
        Intent pendingIntent = pendingFacebookDialogCall.getRequestIntent();

        Intent cancelIntent = new Intent();
        cancelIntent.putExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID,
                pendingIntent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID));
        cancelIntent.putExtra(NativeProtocol.EXTRA_PROTOCOL_ACTION,
                pendingIntent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_ACTION));
        cancelIntent.putExtra(NativeProtocol.EXTRA_PROTOCOL_VERSION,
                pendingIntent.getIntExtra(NativeProtocol.EXTRA_PROTOCOL_VERSION, 0));
        cancelIntent.putExtra(NativeProtocol.STATUS_ERROR_TYPE, NativeProtocol.ERROR_UNKNOWN_ERROR);

        FacebookDialog.handleActivityResult(activity, pendingFacebookDialogCall,
                pendingFacebookDialogCall.getRequestCode(), cancelIntent, facebookDialogCallback);
    }
    pendingFacebookDialogCall = null;
}
 
Example #4
Source File: FacebookDialog.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
@Override
Intent handleBuild(Bundle extras) {
    putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId);
    putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName);
    putExtra(extras, NativeProtocol.EXTRA_TITLE, name);
    putExtra(extras, NativeProtocol.EXTRA_SUBTITLE, caption);
    putExtra(extras, NativeProtocol.EXTRA_DESCRIPTION, description);
    putExtra(extras, NativeProtocol.EXTRA_LINK, link);
    putExtra(extras, NativeProtocol.EXTRA_IMAGE, picture);
    putExtra(extras, NativeProtocol.EXTRA_PLACE_TAG, place);
    putExtra(extras, NativeProtocol.EXTRA_TITLE, name);
    putExtra(extras, NativeProtocol.EXTRA_REF, ref);

    extras.putBoolean(NativeProtocol.EXTRA_DATA_FAILURES_FATAL, dataErrorsFatal);
    if (!Utility.isNullOrEmpty(friends)) {
        extras.putStringArrayList(NativeProtocol.EXTRA_FRIEND_TAGS, friends);
    }

    int protocolVersion = getProtocolVersionForNativeDialog(activity, MIN_NATIVE_SHARE_PROTOCOL_VERSION);

    Intent intent = NativeProtocol.createPlatformActivityIntent(activity, NativeProtocol.ACTION_FEED_DIALOG,
            protocolVersion, extras);
    return intent;
}
 
Example #5
Source File: FacebookDialog.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
@Override
protected Bundle getMethodArguments() {
    Bundle methodArguments = new Bundle();

    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_TITLE, name);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_SUBTITLE, caption);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_DESCRIPTION, description);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_LINK, link);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_IMAGE, picture);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_PLACE_TAG, place);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_TITLE, name);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_REF, ref);

    methodArguments.putBoolean(NativeProtocol.METHOD_ARGS_DATA_FAILURES_FATAL, dataErrorsFatal);
    if (!Utility.isNullOrEmpty(friends)) {
        methodArguments.putStringArrayList(NativeProtocol.METHOD_ARGS_FRIEND_TAGS, friends);
    }

    return methodArguments;
}
 
Example #6
Source File: FacebookDialog.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * Constructs a FacebookDialog with an Intent that is correctly populated to present the dialog within
 * the Facebook application.
 * @return a FacebookDialog instance
 */
public FacebookDialog build() {
    validate();

    Bundle extras = new Bundle();
    putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId);
    putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName);

    Intent intent = handleBuild(extras);
    if (intent == null) {
        throw new FacebookException("Unable to create Intent; this likely means the Facebook app is not installed.");
    }
    appCall.setRequestIntent(intent);

    return new FacebookDialog(activity, fragment, appCall, getOnPresentCallback());
}
 
Example #7
Source File: LoginMethodHandler.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
static AccessToken createAccessTokenFromNativeLogin(
        Bundle bundle,
        AccessTokenSource source,
        String applicationId) {
    Date expires = Utility.getBundleLongAsDate(
            bundle, NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date(0));
    ArrayList<String> permissions = bundle.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
    String token = bundle.getString(NativeProtocol.EXTRA_ACCESS_TOKEN);

    if (Utility.isNullOrEmpty(token)) {
        return null;
    }

    String userId = bundle.getString(NativeProtocol.EXTRA_USER_ID);

    return new AccessToken(
            token,
            applicationId,
            userId,
            permissions,
            null,
            source,
            expires,
            new Date());
}
 
Example #8
Source File: KatanaProxyLoginMethodHandler.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
@Override
boolean tryAuthorize(LoginClient.Request request) {
    String e2e = LoginClient.getE2E();
    Intent intent = NativeProtocol.createProxyAuthIntent(
            loginClient.getActivity(),
            request.getApplicationId(),
            request.getPermissions(),
            e2e,
            request.isRerequest(),
            request.hasPublishPermission(),
            request.getDefaultAudience());

    addLoggingExtra(ServerProtocol.DIALOG_PARAM_E2E, e2e);

    return tryIntent(intent, LoginClient.getLoginRequestCode());
}
 
Example #9
Source File: FacebookDialog.java    From android-skeleton-project with MIT License 6 votes vote down vote up
/**
 * Parses the results of a dialog activity and calls the appropriate method on the provided Callback.
 *
 * @param context     the Context that is handling the activity result
 * @param appCall     an PendingCall containing the call ID and original Intent used to launch the dialog
 * @param requestCode the request code for the activity result
 * @param data        the result Intent
 * @param callback    a callback to call after parsing the results
 * @return true if the activity result was handled, false if not
 */
public static boolean handleActivityResult(Context context, PendingCall appCall, int requestCode, Intent data,
        Callback callback) {
    if (requestCode != appCall.getRequestCode()) {
        return false;
    }

    if (attachmentStore != null) {
        attachmentStore.cleanupAttachmentsForCall(context, appCall.getCallId());
    }

    if (callback != null) {
        if (NativeProtocol.isErrorResult(data)) {
            Exception error = NativeProtocol.getErrorFromResult(data);
            callback.onError(appCall, error, data.getExtras());
        } else {
            callback.onComplete(appCall, data.getExtras());
        }
    }

    return true;
}
 
Example #10
Source File: AuthorizationClient.java    From Klyph with MIT License 6 votes vote down vote up
private Result createCancelOrErrorResult(AuthorizationRequest request, Intent data) {
    Bundle extras = data.getExtras();
    String errorType = extras.getString(NativeProtocol.STATUS_ERROR_TYPE);

    if (NativeProtocol.ERROR_USER_CANCELED.equals(errorType) ||
            NativeProtocol.ERROR_PERMISSION_DENIED.equals(errorType)) {
        return Result.createCancelResult(request, data.getStringExtra(NativeProtocol.STATUS_ERROR_DESCRIPTION));
    } else {
        // See if we can get an error code out of the JSON.
        String errorJson = extras.getString(NativeProtocol.STATUS_ERROR_JSON);
        String errorCode = null;
        if (errorJson != null) {
            try {
                JSONObject jsonObject = new JSONObject(errorJson);
                errorCode = jsonObject.getString("error_code");
            } catch (JSONException e) {
            }
        }
        return Result.createErrorResult(request, errorType,
                data.getStringExtra(NativeProtocol.STATUS_ERROR_DESCRIPTION), errorCode);
    }
}
 
Example #11
Source File: FacebookDialog.java    From facebook-api-android-maven with Apache License 2.0 6 votes vote down vote up
@Override
protected Bundle getMethodArguments() {
    Bundle methodArguments = new Bundle();

    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_TITLE, name);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_SUBTITLE, caption);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_DESCRIPTION, description);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_LINK, link);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_IMAGE, picture);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_PLACE_TAG, place);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_TITLE, name);
    putExtra(methodArguments, NativeProtocol.METHOD_ARGS_REF, ref);

    methodArguments.putBoolean(NativeProtocol.METHOD_ARGS_DATA_FAILURES_FATAL, dataErrorsFatal);
    if (!Utility.isNullOrEmpty(friends)) {
        methodArguments.putStringArrayList(NativeProtocol.METHOD_ARGS_FRIEND_TAGS, friends);
    }

    return methodArguments;
}
 
Example #12
Source File: FacebookDialog.java    From facebook-api-android-maven with Apache License 2.0 6 votes vote down vote up
static private String getEventName(String action, boolean hasPhotos) {
    String eventName;

    if (action.equals(NativeProtocol.ACTION_FEED_DIALOG)) {
        eventName = hasPhotos ?
                AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_PHOTO_SHARE :
                AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_SHARE;
    } else if (action.equals(NativeProtocol.ACTION_MESSAGE_DIALOG)) {
        eventName = hasPhotos ?
                AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_PHOTO_MESSAGE :
                AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_MESSAGE;
    } else if (action.equals(NativeProtocol.ACTION_OGACTIONPUBLISH_DIALOG)) {
        eventName = AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_OG_SHARE;
    } else if (action.equals(NativeProtocol.ACTION_OGMESSAGEPUBLISH_DIALOG)) {
        eventName = AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_OG_MESSAGE;
    } else {
        throw new FacebookException("An unspecified action was presented");
    }
    return eventName;
}
 
Example #13
Source File: FacebookDialog.java    From platform-friends-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
Intent handleBuild(Bundle extras) {
    putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId);
    putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName);
    putExtra(extras, NativeProtocol.EXTRA_TITLE, name);
    putExtra(extras, NativeProtocol.EXTRA_SUBTITLE, caption);
    putExtra(extras, NativeProtocol.EXTRA_DESCRIPTION, description);
    putExtra(extras, NativeProtocol.EXTRA_LINK, link);
    putExtra(extras, NativeProtocol.EXTRA_IMAGE, picture);
    putExtra(extras, NativeProtocol.EXTRA_PLACE_TAG, place);
    putExtra(extras, NativeProtocol.EXTRA_TITLE, name);
    putExtra(extras, NativeProtocol.EXTRA_REF, ref);

    extras.putBoolean(NativeProtocol.EXTRA_DATA_FAILURES_FATAL, dataErrorsFatal);
    if (!Utility.isNullOrEmpty(friends)) {
        extras.putStringArrayList(NativeProtocol.EXTRA_FRIEND_TAGS, friends);
    }

    int protocolVersion = getProtocolVersionForNativeDialog(activity, MIN_NATIVE_SHARE_PROTOCOL_VERSION);

    Intent intent = NativeProtocol.createPlatformActivityIntent(activity, NativeProtocol.ACTION_FEED_DIALOG,
            protocolVersion, extras);
    return intent;
}
 
Example #14
Source File: FacebookDialog.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
static private String getEventName(String action, boolean hasPhotos) {
    String eventName;

    if (action.equals(NativeProtocol.ACTION_FEED_DIALOG)) {
        eventName = hasPhotos ?
                AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_PHOTO_SHARE :
                AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_SHARE;
    } else if (action.equals(NativeProtocol.ACTION_MESSAGE_DIALOG)) {
        eventName = hasPhotos ?
                AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_PHOTO_MESSAGE :
                AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_MESSAGE;
    } else if (action.equals(NativeProtocol.ACTION_OGACTIONPUBLISH_DIALOG)) {
        eventName = AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_OG_SHARE;
    } else if (action.equals(NativeProtocol.ACTION_OGMESSAGEPUBLISH_DIALOG)) {
        eventName = AnalyticsEvents.EVENT_NATIVE_DIALOG_TYPE_OG_MESSAGE;
    } else {
        throw new FacebookException("An unspecified action was presented");
    }
    return eventName;
}
 
Example #15
Source File: AuthorizationClient.java    From KlyphMessenger with MIT License 6 votes vote down vote up
@Override
boolean tryAuthorize(AuthorizationRequest request) {
    applicationId = request.getApplicationId();

    Intent intent = NativeProtocol.createLoginDialog20121101Intent(context, request.getApplicationId(),
            new ArrayList<String>(request.getPermissions()),
            request.getDefaultAudience().getNativeProtocolAudience());
    if (intent == null) {
        return false;
    }

    callId = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID);

    addLoggingExtra(EVENT_EXTRAS_APP_CALL_ID, callId);
    addLoggingExtra(EVENT_EXTRAS_PROTOCOL_VERSION,
            intent.getIntExtra(NativeProtocol.EXTRA_PROTOCOL_VERSION, 0));
    addLoggingExtra(EVENT_EXTRAS_PERMISSIONS,
            TextUtils.join(",", intent.getStringArrayListExtra(NativeProtocol.EXTRA_PERMISSIONS)));
    addLoggingExtra(EVENT_EXTRAS_WRITE_PRIVACY, intent.getStringExtra(NativeProtocol.EXTRA_WRITE_PRIVACY));
    logEvent(AnalyticsEvents.EVENT_NATIVE_LOGIN_DIALOG_START,
            AnalyticsEvents.PARAMETER_NATIVE_LOGIN_DIALOG_START_TIME, callId);

    return tryIntent(intent, request.getRequestCode());
}
 
Example #16
Source File: FacebookDialog.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@Override
Bundle setBundleExtras(Bundle extras) {
    putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId);
    putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName);
    putExtra(extras, NativeProtocol.EXTRA_TITLE, name);
    putExtra(extras, NativeProtocol.EXTRA_SUBTITLE, caption);
    putExtra(extras, NativeProtocol.EXTRA_DESCRIPTION, description);
    putExtra(extras, NativeProtocol.EXTRA_LINK, link);
    putExtra(extras, NativeProtocol.EXTRA_IMAGE, picture);
    putExtra(extras, NativeProtocol.EXTRA_PLACE_TAG, place);
    putExtra(extras, NativeProtocol.EXTRA_TITLE, name);
    putExtra(extras, NativeProtocol.EXTRA_REF, ref);

    extras.putBoolean(NativeProtocol.EXTRA_DATA_FAILURES_FATAL, dataErrorsFatal);
    if (!Utility.isNullOrEmpty(friends)) {
        extras.putStringArrayList(NativeProtocol.EXTRA_FRIEND_TAGS, friends);
    }
    return extras;
}
 
Example #17
Source File: AuthorizationClient.java    From Klyph with MIT License 6 votes vote down vote up
@Override
boolean tryAuthorize(AuthorizationRequest request) {
    applicationId = request.getApplicationId();

    Intent intent = NativeProtocol.createLoginDialog20121101Intent(context, request.getApplicationId(),
            new ArrayList<String>(request.getPermissions()),
            request.getDefaultAudience().getNativeProtocolAudience());
    if (intent == null) {
        return false;
    }

    callId = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID);

    addLoggingExtra(EVENT_EXTRAS_APP_CALL_ID, callId);
    addLoggingExtra(EVENT_EXTRAS_PROTOCOL_VERSION,
            intent.getIntExtra(NativeProtocol.EXTRA_PROTOCOL_VERSION, 0));
    addLoggingExtra(EVENT_EXTRAS_PERMISSIONS,
            TextUtils.join(",", intent.getStringArrayListExtra(NativeProtocol.EXTRA_PERMISSIONS)));
    addLoggingExtra(EVENT_EXTRAS_WRITE_PRIVACY, intent.getStringExtra(NativeProtocol.EXTRA_WRITE_PRIVACY));
    logEvent(AnalyticsEvents.EVENT_NATIVE_LOGIN_DIALOG_START,
            AnalyticsEvents.PARAMETER_NATIVE_LOGIN_DIALOG_START_TIME, callId);

    return tryIntent(intent, request.getRequestCode());
}
 
Example #18
Source File: FacebookDialog.java    From android-skeleton-project with MIT License 6 votes vote down vote up
private void updateActionAttachmentUrls(List<String> attachmentUrls, boolean isUserGenerated) {
    List<JSONObject> attachments = action.getImage();
    if (attachments == null) {
        attachments = new ArrayList<JSONObject>(attachmentUrls.size());
    }

    for (String url : attachmentUrls) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put(NativeProtocol.IMAGE_URL_KEY, url);
            if (isUserGenerated) {
                jsonObject.put(NativeProtocol.IMAGE_USER_GENERATED_KEY, true);
            }
        } catch (JSONException e) {
            throw new FacebookException("Unable to attach images", e);
        }
        attachments.add(jsonObject);
    }
    action.setImage(attachments);
}
 
Example #19
Source File: FacebookDialog.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the results of a dialog activity and calls the appropriate method on the provided Callback.
 *
 * @param context     the Context that is handling the activity result
 * @param appCall     an PendingCall containing the call ID and original Intent used to launch the dialog
 * @param requestCode the request code for the activity result
 * @param data        the result Intent
 * @param callback    a callback to call after parsing the results
 * @return true if the activity result was handled, false if not
 */
public static boolean handleActivityResult(Context context, PendingCall appCall, int requestCode, Intent data,
        Callback callback) {
    if (requestCode != appCall.getRequestCode()) {
        return false;
    }

    if (attachmentStore != null) {
        attachmentStore.cleanupAttachmentsForCall(context, appCall.getCallId());
    }

    if (callback != null) {
        if (NativeProtocol.isErrorResult(data)) {
            Exception error = NativeProtocol.getErrorFromResult(data);

            // TODO  - data.getExtras() doesn't work for the bucketed protocol.
            callback.onError(appCall, error, data.getExtras());
        } else {
            callback.onComplete(appCall, NativeProtocol.getSuccessResultsFromIntent(data));
        }
    }

    return true;
}
 
Example #20
Source File: AuthorizationClient.java    From platform-friends-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Result handleResultOk(Intent data) {
    Bundle extras = data.getExtras();
    String error = extras.getString("error");
    if (error == null) {
        error = extras.getString("error_type");
    }
    String errorCode = extras.getString("error_code");
    String errorMessage = extras.getString("error_message");
    if (errorMessage == null) {
        errorMessage = extras.getString("error_description");
    }

    String e2e = extras.getString(NativeProtocol.FACEBOOK_PROXY_AUTH_E2E_KEY);
    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(applicationId, e2e);
    }

    if (error == null && errorCode == null && errorMessage == null) {
        AccessToken token = AccessToken.createFromWebBundle(pendingRequest.getPermissions(), extras,
                AccessTokenSource.FACEBOOK_APPLICATION_WEB);
        return Result.createTokenResult(pendingRequest, token);
    } else if (ServerProtocol.errorsProxyAuthDisabled.contains(error)) {
        return null;
    } else if (ServerProtocol.errorsUserCanceled.contains(error)) {
        return Result.createCancelResult(pendingRequest, null);
    } else {
        return Result.createErrorResult(pendingRequest, error, errorMessage, errorCode);
    }
}
 
Example #21
Source File: AccessToken.java    From android-skeleton-project with MIT License 5 votes vote down vote up
static AccessToken createFromNativeLogin(Bundle bundle, AccessTokenSource source) {
    Date expires = getBundleLongAsDate(
            bundle, NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date(0));
    ArrayList<String> permissions = bundle.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
    String token = bundle.getString(NativeProtocol.EXTRA_ACCESS_TOKEN);

    return createNew(permissions, token, expires, source);
}
 
Example #22
Source File: UiLifecycleHelper.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
private boolean handleFacebookDialogActivityResult(int requestCode, int resultCode, Intent data,
        FacebookDialog.Callback facebookDialogCallback) {
    if (pendingFacebookDialogCall == null || pendingFacebookDialogCall.getRequestCode() != requestCode) {
        return false;
    }

    if (data == null) {
        // We understand the request code, but have no Intent. This can happen if the called Activity crashes
        // before it can be started; we treat this as a cancellation because we have no other information.
        cancelPendingAppCall(facebookDialogCallback);
        return true;
    }

    String callIdString = data.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID);
    UUID callId = null;
    if (callIdString != null) {
        try {
            callId = UUID.fromString(callIdString);
        } catch (IllegalArgumentException exception) {
        }
    }

    // Was this result for the call we are waiting on?
    if (callId != null && pendingFacebookDialogCall.getCallId().equals(callId)) {
        // Yes, we can handle it normally.
        FacebookDialog.handleActivityResult(activity, pendingFacebookDialogCall, requestCode, data,
                facebookDialogCallback);
    } else {
        // No, send a cancellation error to the pending call and ignore the result, because we
        // don't know what to do with it.
        cancelPendingAppCall(facebookDialogCallback);
    }

    pendingFacebookDialogCall = null;
    return true;
}
 
Example #23
Source File: AuthorizationClient.java    From platform-friends-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Result handleResultOk(Intent data) {
    Bundle extras = data.getExtras();
    String errorType = extras.getString(NativeProtocol.STATUS_ERROR_TYPE);
    if (errorType == null) {
        return Result.createTokenResult(pendingRequest,
                AccessToken.createFromNativeLogin(extras, AccessTokenSource.FACEBOOK_APPLICATION_NATIVE));
    } else if (NativeProtocol.ERROR_SERVICE_DISABLED.equals(errorType)) {
        addLoggingExtra(EVENT_EXTRAS_SERVICE_DISABLED, AppEventsConstants.EVENT_PARAM_VALUE_YES);
        return null;
    } else {
        return createCancelOrErrorResult(pendingRequest, data);
    }
}
 
Example #24
Source File: FacebookDialog.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
private Object flattenObject(Object object) throws JSONException {
    if (object == null) {
        return null;
    }

    if (object instanceof JSONObject) {
        JSONObject jsonObject = (JSONObject) object;

        // Don't flatten objects that are marked as create_object.
        if (jsonObject.optBoolean(NativeProtocol.OPEN_GRAPH_CREATE_OBJECT_KEY)) {
            return object;
        }
        if (jsonObject.has("id")) {
            return jsonObject.getString("id");
        } else if (jsonObject.has("url")) {
            return jsonObject.getString("url");
        }
    } else if (object instanceof JSONArray) {
        JSONArray jsonArray = (JSONArray) object;
        JSONArray newArray = new JSONArray();
        int length = jsonArray.length();

        for (int i = 0; i < length; ++i) {
            newArray.put(flattenObject(jsonArray.get(i)));
        }

        return newArray;
    }

    return object;
}
 
Example #25
Source File: FacebookDialog.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
private Object flattenObject(Object object) throws JSONException {
    if (object == null) {
        return null;
    }

    if (object instanceof JSONObject) {
        JSONObject jsonObject = (JSONObject) object;

        // Don't flatten objects that are marked as create_object.
        if (jsonObject.optBoolean(NativeProtocol.OPEN_GRAPH_CREATE_OBJECT_KEY)) {
            return object;
        }
        if (jsonObject.has("id")) {
            return jsonObject.getString("id");
        } else if (jsonObject.has("url")) {
            return jsonObject.getString("url");
        }
    } else if (object instanceof JSONArray) {
        JSONArray jsonArray = (JSONArray) object;
        JSONArray newArray = new JSONArray();
        int length = jsonArray.length();

        for (int i = 0; i < length; ++i) {
            newArray.put(flattenObject(jsonArray.get(i)));
        }

        return newArray;
    }

    return object;
}
 
Example #26
Source File: k.java    From letv with Apache License 2.0 5 votes vote down vote up
public static String f(Context context) {
    try {
        for (RunningAppProcessInfo runningAppProcessInfo : ((ActivityManager) context.getSystemService("activity")).getRunningAppProcesses()) {
            if (runningAppProcessInfo.processName.contains(b)) {
                return runningAppProcessInfo.processName;
            }
        }
        return null;
    } catch (Throwable th) {
        return NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE;
    }
}
 
Example #27
Source File: UiLifecycleHelper.java    From KlyphMessenger with MIT License 5 votes vote down vote up
private boolean handleFacebookDialogActivityResult(int requestCode, int resultCode, Intent data,
        FacebookDialog.Callback facebookDialogCallback) {
    if (pendingFacebookDialogCall == null || pendingFacebookDialogCall.getRequestCode() != requestCode) {
        return false;
    }

    if (data == null) {
        // We understand the request code, but have no Intent. This can happen if the called Activity crashes
        // before it can be started; we treat this as a cancellation because we have no other information.
        cancelPendingAppCall(facebookDialogCallback);
        return true;
    }

    String callIdString = data.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID);
    UUID callId = null;
    if (callIdString != null) {
        try {
            callId = UUID.fromString(callIdString);
        } catch (IllegalArgumentException exception) {
        }
    }

    // Was this result for the call we are waiting on?
    if (callId != null && pendingFacebookDialogCall.getCallId().equals(callId)) {
        // Yes, we can handle it normally.
        FacebookDialog.handleActivityResult(activity, pendingFacebookDialogCall, requestCode, data,
                facebookDialogCallback);
    } else {
        // No, send a cancellation error to the pending call and ignore the result, because we
        // don't know what to do with it.
        cancelPendingAppCall(facebookDialogCallback);
    }

    pendingFacebookDialogCall = null;
    return true;
}
 
Example #28
Source File: FacebookDialog.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
private Object flattenObject(Object object) throws JSONException {
    if (object == null) {
        return null;
    }

    if (object instanceof JSONObject) {
        JSONObject jsonObject = (JSONObject) object;

        // Don't flatten objects that are marked as create_object.
        if (jsonObject.optBoolean(NativeProtocol.OPEN_GRAPH_CREATE_OBJECT_KEY)) {
            return object;
        }
        if (jsonObject.has("id")) {
            return jsonObject.getString("id");
        } else if (jsonObject.has("url")) {
            return jsonObject.getString("url");
        }
    } else if (object instanceof JSONArray) {
        JSONArray jsonArray = (JSONArray) object;
        JSONArray newArray = new JSONArray();
        int length = jsonArray.length();

        for (int i = 0; i < length; ++i) {
            newArray.put(flattenObject(jsonArray.get(i)));
        }

        return newArray;
    }

    return object;
}
 
Example #29
Source File: AuthorizationClient.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
void getTokenCompleted(AuthorizationRequest request, Bundle result) {
    getTokenClient = null;

    notifyBackgroundProcessingStop();

    if (result != null) {
        ArrayList<String> currentPermissions = result.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
        List<String> permissions = request.getPermissions();
        if ((currentPermissions != null) &&
                ((permissions == null) || currentPermissions.containsAll(permissions))) {
            // We got all the permissions we needed, so we can complete the auth now.
            AccessToken token = AccessToken
                    .createFromNativeLogin(result, AccessTokenSource.FACEBOOK_APPLICATION_SERVICE);
            Result outcome = Result.createTokenResult(pendingRequest, token);
            completeAndValidate(outcome);
            return;
        }

        // We didn't get all the permissions we wanted, so update the request with just the permissions
        // we still need.
        List<String> newPermissions = new ArrayList<String>();
        for (String permission : permissions) {
            if (!currentPermissions.contains(permission)) {
                newPermissions.add(permission);
            }
        }
        if (!newPermissions.isEmpty()) {
            addLoggingExtra(EVENT_EXTRAS_NEW_PERMISSIONS, TextUtils.join(",", newPermissions));
        }

        request.setPermissions(newPermissions);
    }

    tryNextHandler();
}
 
Example #30
Source File: AccessToken.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
static AccessToken createFromNativeLogin(Bundle bundle, AccessTokenSource source) {
    Date expires = getBundleLongAsDate(
            bundle, NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date(0));
    ArrayList<String> permissions = bundle.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
    String token = bundle.getString(NativeProtocol.EXTRA_ACCESS_TOKEN);

    return createNew(permissions, null, token, expires, source);
}