public void ShareImageOnFacebook(string caption, string imagePath)
        {
            SharePhoto tt = SharePhoto.From(new UIImage(imagePath), true);

            tt.Caption = caption;
            SharePhotoContent content = new SharePhotoContent();

            content.Photos = new SharePhoto[] { tt };
            content.SetContentUrl(new NSUrl(imagePath));

            var shareDelegate = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.FeedBrowser;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(content);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;

            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Mode = ShareDialogMode.Native;
                dialog.Show();
            }
            else
            {
                ShareAPI.Share(content, shareDelegate);
            }
        }
        public void ShareLinkOnFacebook(string text, string description, string link)
        {
            ShareLinkContent link1 = new ShareLinkContent();

            link1.SetContentUrl(new NSUrl(link));
            var shareDelegate = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.FeedBrowser;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(link1);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Mode = ShareDialogMode.Native;
                dialog.Show();
            }
            else
            {
                ShareAPI.Share(link1, shareDelegate);
            }
        }
        public void ShareTextOnFacebook(string text)
        {
            ShareLinkContent link = new ShareLinkContent();
            var shareDelegate     = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.Native;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(link);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Show();
            }
            else
            {
                new UIAlertView("Error", "Cannot share text when app is not installed", null, "Ok", null).Show();
            }
        }
        public async void SendOpenGraph(object source, ChallengeModel model, string message = null)
        {
            ShareTemplateModel shareTemplate = null;
            ShareResponseModel shareResponse = null;

            await SL.Manager.RefreshShareTemplate(model.ShareTemplateURL, (response) =>
            {
                shareTemplate = response?.ShareTemplate;
                shareResponse = response;
            });

            NSUrl url = new NSUrl(shareTemplate?.PostHref ?? model.ShareImage);

            if (string.IsNullOrEmpty(url?.AbsoluteString))
            {
                new UIAlertView("Sharing Error", string.IsNullOrEmpty(shareResponse?.ResponseMessage) ? "Sorry. No url come from server" : shareResponse.ResponseMessage, source as IUIAlertViewDelegate, "Ok").Show();
                return;
            }

            ShareDialog dialog = new ShareDialog();

            dialog.SetShouldFailOnDataError(true);
            dialog.FromViewController = source as UIViewController;
            dialog.SetDelegate(source as ISharingDelegate ?? new FBSharingDelegate());

            NSString[] keys;
            NSObject[] objects;

            string imgUrl = null;

            try
            {
                if (!string.IsNullOrEmpty(model.ShareImage))
                {
                    await ImageService.Instance.LoadUrl(model.ShareImage).IntoAsync(new UIImageView());

                    imgUrl = model.ShareImage;
                }
            }
            catch (Exception) { }

            if (string.IsNullOrEmpty(imgUrl))
            {
                keys = new NSString[] {
                    new NSString("og:type"),
                    new NSString("og:url"),
                    new NSString("og:title"),
                    new NSString("og:description"),
                };
                objects = new NSObject[] {
                    NSObject.FromObject("article"),
                    NSObject.FromObject(url),
                    NSObject.FromObject(string.IsNullOrEmpty(shareTemplate?.PostTitle) ? url.AbsoluteString : shareTemplate.PostTitle),
                    NSObject.FromObject(string.IsNullOrEmpty(message) ? shareTemplate?.PostDescription ?? " " : message),
                };
            }
            else
            {
                keys = new NSString[] {
                    new NSString("og:type"),
                    new NSString("og:url"),
                    new NSString("og:title"),
                    new NSString("og:description"),
                    new NSString("og:image"),
                };
                objects = new NSObject[]
                {
                    NSObject.FromObject("article"),
                    NSObject.FromObject(url),
                    NSObject.FromObject(string.IsNullOrEmpty(shareTemplate?.PostTitle) ? url.AbsoluteString : shareTemplate.PostTitle),
                    NSObject.FromObject(string.IsNullOrEmpty(message) ? shareTemplate?.PostDescription ?? " " : message),
                    NSObject.FromObject(imgUrl),
                };
            }

            var propesties       = new NSDictionary <NSString, NSObject>(keys, objects);
            var openGraph        = ShareOpenGraphObject.ObjectWithProperties(propesties);
            var action           = ShareOpenGraphAction.Action("news.publishes", openGraph, "article");
            var contentOpenGraph = new ShareOpenGraphContent
            {
                Action = action,
                PreviewPropertyName = "article"
            };

            dialog.SetShareContent(contentOpenGraph);
            dialog.Mode = ShareDialogMode.Web;

            dialog.Show();

            if (dialog.Mode == ShareDialogMode.Web)
            {
                StylishFbWebDialog();
            }
        }
        public async void ShareFacebookChallenge(object source, ChallengeModel model, string message = null)
        {
            ShareTemplateModel shareTemplate = null;
            ShareResponseModel shareResponse = null;
            await SL.Manager.RefreshShareTemplate(model.ShareTemplateURL, (response) =>
            {
                shareTemplate = response?.ShareTemplate;
                shareResponse = response;
            });

            NSUrl url = new NSUrl(shareTemplate?.PostHref ?? model.ShareImage);

            ShareDialog dialog = new ShareDialog();

            dialog.SetShouldFailOnDataError(true);
            dialog.FromViewController = source as UIViewController;
            dialog.SetDelegate(source as ISharingDelegate ?? new FBSharingDelegate());

            if (string.IsNullOrEmpty(message) && model.FBShareType == "image")
            {
                UIImageView imageView = new UIImageView();
                try
                {
                    await ImageService.Instance.LoadUrl(model.ShareImage).IntoAsync(imageView);
                }
                catch (Exception)
                {
                    try
                    {
                        await ImageService.Instance.LoadUrl(model.Image).IntoAsync(imageView);
                    }
                    catch (Exception)
                    {
                    }
                }

                dialog.SetShareContent(new SharePhotoContent()
                {
                    Photos = new SharePhoto[] { SharePhoto.From(imageView.Image, true) }
                });
                dialog.Mode = ShareDialogMode.Native;
            }
            else if (string.IsNullOrEmpty(message) && (model.FBShareType == "link" || model.FBShareType == null))
            {
                ShareLinkContent contentLink = new ShareLinkContent();
                if (string.IsNullOrEmpty(url?.AbsoluteString))
                {
                    new UIAlertView("Sharing Error", string.IsNullOrEmpty(shareResponse?.ResponseMessage) ? "Sorry. No url come from server" : shareResponse.ResponseMessage, source as IUIAlertViewDelegate, "Ok").Show();
                    return;
                }
                contentLink.SetContentUrl(url);

                dialog.SetShareContent(contentLink);
                dialog.Mode = ShareDialogMode.Web;
            }
            else
            {
                SendOpenGraph(source, model, message);
                return;
            }

            if (!dialog.CanShow())
            {
                SendOpenGraph(source, model, message);
                return;
            }
            dialog.Show();

            if (dialog.Mode == ShareDialogMode.Web)
            {
                StylishFbWebDialog();
            }
        }