Java 类com.facebook.internal.NativeProtocol 实例源码

项目:kognitivo    文件:ShareInternalUtility.java   
public static JSONObject toJSONObjectForWeb(
        final ShareOpenGraphContent shareOpenGraphContent)
        throws JSONException {
    ShareOpenGraphAction action = shareOpenGraphContent.getAction();

    return OpenGraphJSONUtility.toJSONObject(
            action,
            new OpenGraphJSONUtility.PhotoJSONProcessor() {
                @Override
                public JSONObject toJSONObject(SharePhoto photo) {
                    Uri photoUri = photo.getImageUrl();
                    JSONObject photoJSONObject = new JSONObject();
                    try {
                        photoJSONObject.put(
                                NativeProtocol.IMAGE_URL_KEY, photoUri.toString());
                    } catch (JSONException e) {
                        throw new FacebookException("Unable to attach images", e);
                    }
                    return photoJSONObject;
                }
            });
}
项目:kognitivo    文件:LoginMethodHandler.java   
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());
}
项目:kognitivo    文件:KatanaProxyLoginMethodHandler.java   
@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());
}
项目:kognitivo    文件:FacebookActivity.java   
private void handlePassThroughError() {
    Intent requestIntent = getIntent();

    // The error we need to respond with is passed to us as method arguments.
    Bundle errorResults = NativeProtocol.getMethodArgumentsFromIntent(requestIntent);
    FacebookException exception = NativeProtocol.getExceptionFromErrorData(errorResults);

    // Create a result intent that is formed based on the request intent
    Intent resultIntent = NativeProtocol.createProtocolResultIntent(
            requestIntent,
            null,
            exception);

    setResult(RESULT_CANCELED, resultIntent);
    finish();
}
项目:AndroidBackendlessChat    文件:UiLifecycleHelper.java   
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;
}
项目:AndroidBackendlessChat    文件:FacebookDialog.java   
/**
 * 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;
}
项目:AndroidBackendlessChat    文件:FacebookDialog.java   
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;
}
项目:AndroidBackendlessChat    文件:FacebookDialog.java   
/**
 * 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);
    extras = setBundleExtras(extras);

    String action = getActionForFeatures(getDialogFeatures());
    int protocolVersion = getProtocolVersionForNativeDialog(activity, action,
            getMinVersionForFeatures(getDialogFeatures()));

    Intent intent = NativeProtocol.createPlatformActivityIntent(activity, action, protocolVersion, extras);
    if (intent == null) {
        logDialogActivity(activity, fragment,
                getEventName(action, extras.containsKey(NativeProtocol.EXTRA_PHOTOS)),
                AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_FAILED);

        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());
}
项目:AndroidBackendlessChat    文件:FacebookDialog.java   
@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;
}
项目:AndroidBackendlessChat    文件:FacebookDialog.java   
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);
}
项目:chat-sdk-android-push-firebase    文件:UiLifecycleHelper.java   
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;
}
项目:chat-sdk-android-push-firebase    文件:FacebookDialog.java   
/**
 * 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;
}
项目:chat-sdk-android-push-firebase    文件:FacebookDialog.java   
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;
}
项目:chat-sdk-android-push-firebase    文件:FacebookDialog.java   
/**
 * 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);
    extras = setBundleExtras(extras);

    String action = getActionForFeatures(getDialogFeatures());
    int protocolVersion = getProtocolVersionForNativeDialog(activity, action,
            getMinVersionForFeatures(getDialogFeatures()));

    Intent intent = NativeProtocol.createPlatformActivityIntent(activity, action, protocolVersion, extras);
    if (intent == null) {
        logDialogActivity(activity, fragment,
                getEventName(action, extras.containsKey(NativeProtocol.EXTRA_PHOTOS)),
                AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_FAILED);

        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());
}
项目:chat-sdk-android-push-firebase    文件:FacebookDialog.java   
@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;
}
项目:chat-sdk-android-push-firebase    文件:FacebookDialog.java   
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);
}
项目:Move-Alarm_ORCA    文件:ShareInternalUtility.java   
public static JSONObject toJSONObjectForWeb(
        final ShareOpenGraphContent shareOpenGraphContent)
        throws JSONException {
    ShareOpenGraphAction action = shareOpenGraphContent.getAction();

    return OpenGraphJSONUtility.toJSONObject(
            action,
            new OpenGraphJSONUtility.PhotoJSONProcessor() {
                @Override
                public JSONObject toJSONObject(SharePhoto photo) {
                    Uri photoUri = photo.getImageUrl();
                    JSONObject photoJSONObject = new JSONObject();
                    try {
                        photoJSONObject.put(
                                NativeProtocol.IMAGE_URL_KEY, photoUri.toString());
                    } catch (JSONException e) {
                        throw new FacebookException("Unable to attach images", e);
                    }
                    return photoJSONObject;
                }
            });
}
项目:Move-Alarm_ORCA    文件:FacebookActivity.java   
private void handlePassThroughError() {
    Intent requestIntent = getIntent();

    // The error we need to respond with is passed to us as method arguments.
    Bundle errorResults = NativeProtocol.getMethodArgumentsFromIntent(requestIntent);
    FacebookException exception = NativeProtocol.getExceptionFromErrorData(errorResults);

    // Create a result intent that is formed based on the request intent
    Intent resultIntent = NativeProtocol.createProtocolResultIntent(
            requestIntent,
            null,
            exception);

    setResult(RESULT_CANCELED, resultIntent);
    finish();
}
项目:yelo-android    文件:AuthorizationClient.java   
@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());
}
项目:yelo-android    文件:UiLifecycleHelper.java   
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;
}
项目:yelo-android    文件:FacebookDialog.java   
@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;
}
项目:yelo-android    文件:FacebookDialog.java   
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);
}
项目:yelo-android    文件:FacebookDialog.java   
@Override
Intent handleBuild(Bundle extras)  {
    putExtra(extras, NativeProtocol.EXTRA_PREVIEW_PROPERTY_NAME, previewPropertyName);
    putExtra(extras, NativeProtocol.EXTRA_ACTION_TYPE, actionType);
    extras.putBoolean(NativeProtocol.EXTRA_DATA_FAILURES_FATAL, dataErrorsFatal);

    JSONObject jsonAction = action.getInnerJSONObject();
    jsonAction = flattenChildrenOfGraphObject(jsonAction);

    String jsonString = jsonAction.toString();
    putExtra(extras, NativeProtocol.EXTRA_ACTION, jsonString);

    int protocolVersion = getProtocolVersionForNativeDialog(activity, MIN_NATIVE_SHARE_PROTOCOL_VERSION);

    Intent intent = NativeProtocol.createPlatformActivityIntent(activity,
            NativeProtocol.ACTION_OGACTIONPUBLISH_DIALOG, protocolVersion, extras);

    return intent;
}
项目:snake-game-aws    文件:FacebookDialog.java   
/**
 * 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);
    extras = setBundleExtras(extras);

    String action = getActionForFeatures(getDialogFeatures());
    int protocolVersion = getProtocolVersionForNativeDialog(activity, action,
            getMinVersionForFeatures(getDialogFeatures()));

    Intent intent = NativeProtocol.createPlatformActivityIntent(activity, action, protocolVersion, extras);
    if (intent == null) {
        logDialogActivity(activity, fragment,
                getEventName(action, extras.containsKey(NativeProtocol.EXTRA_PHOTOS)),
                AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_FAILED);

        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());
}
项目:aquaplay    文件:AuthorizationClient.java   
@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());
}
项目:snake-game-aws    文件:UiLifecycleHelper.java   
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;
}
项目:aquaplay    文件:UiLifecycleHelper.java   
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;
}
项目:aquaplay    文件:FacebookDialog.java   
/**
 * 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());
}
项目:aquaplay    文件:FacebookDialog.java   
@Override
Intent handleBuild(Bundle extras)  {
    putExtra(extras, NativeProtocol.EXTRA_PREVIEW_PROPERTY_NAME, previewPropertyName);
    putExtra(extras, NativeProtocol.EXTRA_ACTION_TYPE, actionType);
    extras.putBoolean(NativeProtocol.EXTRA_DATA_FAILURES_FATAL, dataErrorsFatal);

    JSONObject jsonAction = action.getInnerJSONObject();
    jsonAction = flattenChildrenOfGraphObject(jsonAction);

    String jsonString = jsonAction.toString();
    putExtra(extras, NativeProtocol.EXTRA_ACTION, jsonString);

    int protocolVersion = getProtocolVersionForNativeDialog(activity, MIN_NATIVE_SHARE_PROTOCOL_VERSION);

    Intent intent = NativeProtocol.createPlatformActivityIntent(activity,
            NativeProtocol.ACTION_OGACTIONPUBLISH_DIALOG, protocolVersion, extras);

    return intent;
}
项目:kognitivo    文件:FacebookBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    String appCallId = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID);
    String action = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_ACTION);
    if (appCallId != null && action != null) {
        Bundle extras = intent.getExtras();

        if (NativeProtocol.isErrorResult(intent)) {
            onFailedAppCall(appCallId, action, extras);
        } else {
            onSuccessfulAppCall(appCallId, action, extras);
        }
    }
}
项目:kognitivo    文件:LikeActionController.java   
/**
 * Only to be called after an OG-publish was attempted and something went wrong. The Button
 * state is reverted and an error is returned to the LikeViews
 */
private void publishDidError(boolean oldLikeState) {
    updateLikeState(oldLikeState);

    Bundle errorBundle = new Bundle();
    errorBundle.putString(
            NativeProtocol.STATUS_ERROR_DESCRIPTION,
            ERROR_PUBLISH_ERROR);

    broadcastAction(
            LikeActionController.this,
            ACTION_LIKE_ACTION_CONTROLLER_DID_ERROR,
            errorBundle);
}
项目:kognitivo    文件:LikeStatusClient.java   
LikeStatusClient(Context context, String applicationId, String objectId) {
    super(context,
            NativeProtocol.MESSAGE_GET_LIKE_STATUS_REQUEST,
            NativeProtocol.MESSAGE_GET_LIKE_STATUS_REPLY,
            NativeProtocol.PROTOCOL_VERSION_20141001,
            applicationId);

    this.objectId = objectId;
}
项目:kognitivo    文件:ShareInternalUtility.java   
public static boolean handleActivityResult(
        int requestCode,
        int resultCode,
        Intent data,
        ResultProcessor resultProcessor) {
    AppCall appCall = getAppCallFromActivityResult(requestCode, resultCode, data);
    if (appCall == null) {
        return false;
    }

    NativeAppCallAttachmentStore.cleanupAttachmentsForCall(appCall.getCallId());
    if (resultProcessor == null) {
        return true;
    }

    FacebookException exception = NativeProtocol.getExceptionFromErrorData(
            NativeProtocol.getErrorDataFromResultIntent(data));
    if (exception != null) {
        if (exception instanceof FacebookOperationCanceledException) {
            resultProcessor.onCancel(appCall);
        } else {
            resultProcessor.onError(appCall, exception);
        }
    } else {
        // If here, we did not find an error in the result.
        Bundle results = NativeProtocol.getSuccessResultsFromIntent(data);
        resultProcessor.onSuccess(appCall, results);
    }

    return true;
}
项目:kognitivo    文件:ShareInternalUtility.java   
private static AppCall getAppCallFromActivityResult(int requestCode,
                                                    int resultCode,
                                                    Intent data) {
    UUID callId = NativeProtocol.getCallIdFromIntent(data);
    if (callId == null) {
        return null;
    }

    return AppCall.finishPendingCall(callId, requestCode);
}
项目:kognitivo    文件:KatanaProxyLoginMethodHandler.java   
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);
    }
}
项目:kognitivo    文件:GetTokenLoginMethodHandler.java   
void getTokenCompleted(LoginClient.Request request, Bundle result) {
    if (getTokenClient != null) {
        getTokenClient.setCompletedListener(null);
    }
    getTokenClient = null;

    loginClient.notifyBackgroundProcessingStop();

    if (result != null) {
        ArrayList<String> currentPermissions =
                result.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
        Set<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.
            complete(request, result);
            return;
        }

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

        request.setPermissions(newPermissions);
    }

    loginClient.tryNextHandler();
}
项目:kognitivo    文件:GetTokenClient.java   
GetTokenClient(Context context, String applicationId) {
    super(
            context,
            NativeProtocol.MESSAGE_GET_ACCESS_TOKEN_REQUEST,
            NativeProtocol.MESSAGE_GET_ACCESS_TOKEN_REPLY,
            NativeProtocol.PROTOCOL_VERSION_20121101,
            applicationId);
}
项目:kognitivo    文件:GraphUtil.java   
/**
 * Creates a JSONObject for an open graph object that is suitable for posting.
 * @param type the Open Graph object type for the object, or null if it will be specified later
 * @param title the title of the object, or null if it will be specified later
 * @param imageUrl the URL of an image associated with the object, or null
 * @param url the URL associated with the object, or null
 * @param description the description of the object, or null
 * @param objectProperties the properties of the open graph object
 * @param id the id of the object if the post is for update
 * @return a JSONObject
 */
public static JSONObject createOpenGraphObjectForPost(
        String type,
        String title,
        String imageUrl,
        String url,
        String description,
        JSONObject objectProperties,
        String id) {
    JSONObject openGraphObject = new JSONObject();
    try {
        if (type != null) {
            openGraphObject.put("type", type);
        }
        openGraphObject.put("title", title);

        if (imageUrl != null) {
            JSONObject imageUrlObject = new JSONObject();
            imageUrlObject.put("url", imageUrl);
            JSONArray imageUrls = new JSONArray();
            imageUrls.put(imageUrlObject);
            openGraphObject.put("image", imageUrls);
        }

        openGraphObject.put("url", url);
        openGraphObject.put("description", description);
        openGraphObject.put(NativeProtocol.OPEN_GRAPH_CREATE_OBJECT_KEY, true);

        if (objectProperties != null) {
            openGraphObject.put("data", objectProperties);
        }

        if (id != null) {
            openGraphObject.put("id", id);
        }
    } catch (JSONException e) {
        throw new FacebookException("An error occurred while setting up the graph object", e);
    }
    return openGraphObject;
}
项目:AndroidBackendlessChat    文件:FacebookBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    String appCallId = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_CALL_ID);
    String action = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_ACTION);
    if (appCallId != null && action != null) {
        Bundle extras = intent.getExtras();

        if (NativeProtocol.isErrorResult(intent)) {
            onFailedAppCall(appCallId, action, extras);
        } else {
            onSuccessfulAppCall(appCallId, action, extras);
        }
    }
}
项目:AndroidBackendlessChat    文件:AuthorizationClient.java   
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();
}