public async Task SendOpenGraph(object source, ChallengeModel model, string message = null, byte[] data = null, Action <ChallengesFacebookShareResponseType> viewModelResponse = null, ShareTemplateModel shareTemplate = null, ShareResponseModel shareResponse = null) { ViewModelResponse = viewModelResponse; ShareDialog dialog = new ShareDialog(source as Activity); dialog.RegisterCallback((source as MainActivity).CallBackManager, this); if (shareTemplate == null || shareResponse == null) { await SL.Manager.RefreshShareTemplate(model.ShareTemplateURL, (response) => { ShareTemplate = response?.ShareTemplate; shareResponse = response; }); } else { ShareTemplate = shareTemplate; } OpenGraphWasTry = true; var openGraphBuilder = new ShareOpenGraphObject.Builder(); openGraphBuilder.PutString("og:type", "object"); openGraphBuilder.PutString("og:title", string.IsNullOrEmpty(ShareTemplate?.PostTitle) ? ShareTemplate?.PostHref : ShareTemplate.PostTitle); openGraphBuilder.PutString("og:description", string.IsNullOrEmpty(message) ? ShareTemplate?.PostDescription ?? " " : message); //openGraphBuilder.PutString("og:url", ShareTemplate?.PostHref ?? model.ShareImage); if (model != null && (model.FBShareType == "image" || !string.IsNullOrEmpty(model.ShareImage))) { openGraphBuilder.PutString("og:image", model.ShareImage); } if (model != null && (model.FBShareType == "link" || model.FBShareType == null)) { openGraphBuilder.PutString("og:url", ShareTemplate?.PostHref ?? model.ShareImage); } ShareOpenGraphObject openGraph = openGraphBuilder.Build(); ShareOpenGraphAction action = new ShareOpenGraphAction.Builder() .SetActionType("news.publishes") .PutObject("object", openGraph) .JavaCast <ShareOpenGraphAction.Builder>() .Build(); ShareOpenGraphContent contentOpenGraph = new ShareOpenGraphContent.Builder() .SetPreviewPropertyName("object") .SetAction(action) .Build(); dialog.Show(contentOpenGraph, ShareDialog.Mode.Web); //ShareDialog.Show(source as Activity, contentOpenGraph); }
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(); } }