public void shareFacebook(View v) { Fragment prev = getSupportFragmentManager().findFragmentByTag("alertacompartir"); if (prev != null) { DialogFragment df = (DialogFragment) prev; df.dismiss(); } if (FacebookDialog.canPresentShareDialog( getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) .setLink(getResources().getString(R.string.url)) .setDescription(getResources().getString(R.string.textofacebook)) .setName(getResources().getString(R.string.app_name)) .setPicture(getResources().getString(R.string.app_imagen_url)) .build(); uiHelper.trackPendingDialogCall(shareDialog.present()); } else { Toast.makeText( getApplicationContext(), "No se puede compartir en facebook porque no tenes instalada la app de facebook", Toast.LENGTH_LONG) .show(); } }
public void shareOnFacebook(int level, long score, int obstacles) { String modo = getResources().getString(R.string.easy); if (level == 1) modo = getResources().getString(R.string.normal); else if (level == 2) modo = getResources().getString(R.string.hard); String name = "Turbo Race"; String caption = getResources().getString(R.string.caption); String picture = "http://carlospinan.com/icon/turbo_race.png"; String description = getResources().getString(R.string.fb_description); description = description.replace("{score}", score + ""); description = description.replace("{modo}", modo + ""); description = description.replace("{obstaculos}", obstacles + ""); String link = "https://play.google.com/store/apps/details?id=com.carlospinan.turborace"; if (FacebookDialog.canPresentShareDialog( getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { // Publish the post using the Share Dialog FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) .setLink(link) .setName(name) .setCaption(caption) .setPicture(picture) .setDescription(description) .build(); uiHelper.trackPendingDialogCall(shareDialog.present()); } else { // Fallback. For example, publish the post using the Feed Dialog publishFeedDialog(name, caption, description, link, picture); } }
@Override protected void executeImpl() { if (FacebookDialog.canPresentShareDialog( sessionManager.getActivity(), ShareDialogFeature.PHOTOS)) { FacebookDialog shareDialog = new FacebookDialog.PhotoShareDialogBuilder(sessionManager.getActivity()) .addPhotos(Utils.extractBitmaps(mPhotos)) .setPlace(mPlace) .build(); PendingCall pendingCall = shareDialog.present(); sessionManager.trackFacebookDialogPendingCall( pendingCall, new FacebookDialog.Callback() { @Override public void onError(PendingCall pendingCall, Exception error, Bundle data) { sessionManager.untrackPendingCall(); Logger.logError( PublishPhotoDialogAction.class, "Failed to share by using native dialog", error); if ("".equals(error.getMessage())) { Logger.logError( PublishPhotoDialogAction.class, "Make sure to have 'app_id' meta data value in your manifest", error); } mOnPublishListener.onFail( "Have you added com.facebook.NativeAppCallContentProvider to your manifest? " + error.getMessage()); } @Override public void onComplete(PendingCall pendingCall, Bundle data) { sessionManager.untrackPendingCall(); boolean didComplete = FacebookDialog.getNativeDialogDidComplete(data); String postId = FacebookDialog.getNativeDialogPostId(data); String completeGesture = FacebookDialog.getNativeDialogCompletionGesture(data); if (completeGesture != null) { if (completeGesture.equals("post")) { mOnPublishListener.onComplete(postId != null ? postId : "no postId return"); } else { mOnPublishListener.onFail("Canceled by user"); } } else if (didComplete) { mOnPublishListener.onComplete( postId != null ? postId : "published successfully. (post id is not availaible if you are not logged in)"); } else { mOnPublishListener.onFail("Canceled by user"); } } }); } else { mOnPublishListener.onFail("Photos sharing dialog isn't supported"); } }
private void share() { if (FacebookDialog.canPresentShareDialog( getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { dialog.show(); // Publish the post using the Share Dialog FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) .setLink(getLink()) .setName(getName()) .setDescription(getMessage()) .setPicture(currentView.getImageUrl()) .build(); uiHelper.trackPendingDialogCall(shareDialog.present()); } else { publishFeedDialog(); } }
@Override protected void executeImpl() { if (FacebookDialog.canPresentOpenGraphActionDialog( sessionManager.getActivity(), OpenGraphActionDialogFeature.OG_ACTION_DIALOG)) { FacebookDialog shareDialog = null; /* * Publishing open graph can be in 2 ways: 1. Publish actions on * app-owned objects Means, you as developer of the app define Open * Graph Object on your server with <meta> tags or you have * published object to facebook server. This is predefined Object * and user can't change it. 2. Publish actions on user-owned * objects You didn't add anything to server, but you give the user * the option to define Object Graph properties from the app and * publish it. */ String objectId = mStory.getStoryObject().getId(); String objectUrl = mStory.getStoryObject().getHostedUrl(); final boolean predefineObject; if (objectId != null || objectUrl != null) { predefineObject = true; } else { predefineObject = false; } // set the option 1 if (predefineObject) { OpenGraphAction action = OpenGraphAction.Factory.createForPost(mStory.getPath()); action.setProperty( mStory.getStoryObject().getNoun(), objectId != null ? objectId : objectUrl); Iterator<String> actionProperties = mStory.getStoryAction().getParams().keySet().iterator(); while (actionProperties.hasNext()) { String property = actionProperties.next(); action.setProperty(property, mStory.getStoryAction().getParams().get(property)); } // set share dialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder( sessionManager.getActivity(), action, mStory.getStoryObject().getNoun()) .build(); } else { // set the option 2 OpenGraphObject object = OpenGraphObject.Factory.createForPost(mStory.getObjectType()); Iterator<String> objectProperties = mStory.getStoryObject().getObjectProperties().keySet().iterator(); while (objectProperties.hasNext()) { String property = objectProperties.next(); object.setProperty(property, mStory.getStoryObject().getObjectProperties().get(property)); } // set custom object properties GraphObject data = mStory.getStoryObject().getData(); if (data != null) { for (Entry<String, Object> property : data.asMap().entrySet()) { object.getData().setProperty(property.getKey(), property.getValue()); } } OpenGraphAction action = OpenGraphAction.Factory.createForPost(mStory.getPath()); action.setProperty(mStory.getStoryObject().getNoun(), object); // set custom action properties Iterator<String> actionProperties = mStory.getStoryAction().getParams().keySet().iterator(); while (actionProperties.hasNext()) { String property = actionProperties.next(); action.setProperty(property, mStory.getStoryAction().getParams().get(property)); } shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder( sessionManager.getActivity(), action, mStory.getStoryObject().getNoun()) .build(); } PendingCall pendingCall = shareDialog.present(); sessionManager.trackFacebookDialogPendingCall( pendingCall, new FacebookDialog.Callback() { @Override public void onError(PendingCall pendingCall, Exception error, Bundle data) { sessionManager.untrackPendingCall(); Logger.logError( PublishStoryDialogAction.class, "Failed to share by using native dialog", error); if ("".equals(error.getMessage())) { Logger.logError( PublishStoryDialogAction.class, "Make sure to have 'app_id' meta data value in your manifest", error); } mOnPublishListener.onFail( "Have you added com.facebook.NativeAppCallContentProvider to your manifest? " + error.getMessage()); } @Override public void onComplete(PendingCall pendingCall, Bundle data) { sessionManager.untrackPendingCall(); boolean didComplete = FacebookDialog.getNativeDialogDidComplete(data); String postId = FacebookDialog.getNativeDialogPostId(data); String completeGesture = FacebookDialog.getNativeDialogCompletionGesture(data); if (completeGesture != null) { if (completeGesture.equals("post")) { mOnPublishListener.onComplete(postId != null ? postId : "no postId return"); } else { mOnPublishListener.onFail("Canceled by user"); } } else if (didComplete) { mOnPublishListener.onComplete( postId != null ? postId : "published successfully. (post id is not availaible if you are not logged in)"); } else { mOnPublishListener.onFail("Canceled by user"); } } }); } else { mOnPublishListener.onFail("Open graph sharing dialog isn't supported"); } }