/// <summary>Shares a short story consisting of a link and some information on facebook.</summary> /// <returns>A promise with a bundle optionally containing {postId: "<the post ID on facebook>"}.</returns> /// <param name="url">The URL to which this post should link.</param> /// <param name="title">The desired title of the content in the link.</param> /// <param name="description">A short description, rendered below title in the story.</param> /// <param name="photoUrl">A URL for the thumbnail image that appears on the post.</param> public Promise <Bundle> ShareLink(string url = null, string title = "", string description = "", string photoUrl = null) { var task = new Promise <Bundle>(); DoOnGUI.Add(() => { Uri uri = url != null ? new Uri(url) : null; Uri photoUri = photoUrl != null ? new Uri(photoUrl) : null; FB.ShareLink(uri, title, description, photoUri, shareResult => { if (shareResult.Cancelled || !String.IsNullOrEmpty(shareResult.Error)) { task.PostResult(ErrorCode.Canceled, "Facebook share canceled"); } else if (!String.IsNullOrEmpty(shareResult.PostId)) { // Print post identifier of the shared content task.PostResult(Bundle.CreateObject("postId", shareResult.PostId)); } else { // Share succeeded without postID task.PostResult(Bundle.Empty); } }); }); return(task); }
void OnGUI() { if (!FbIsLoaded) { return; } lock (DoOnGUI) { // Run pending actions and resolve promises foreach (var a in DoOnGUI) { a(); } DoOnGUI.Clear(); } }
/// <summary> /// Logs in to Facebook and returns an access token (FB API) that can be used to log in with CotC. /// </summary> /// <returns>task returning a facebook access token in case of success.</returns> /// <param name="permissions">List of permissions to request for.</param> public Promise <AccessToken> LoginToFacebook(List <string> permissions) { var task = new Promise <AccessToken>(); DoOnGUI.Add(() => { FB.LogInWithReadPermissions(permissions, (ILoginResult result) => { if (result.Error != null) { task.PostResult(ErrorCode.SocialNetworkError, "Facebook/ " + result.Error); } else if (!FB.IsLoggedIn) { task.PostResult(ErrorCode.LoginCanceled, "Login canceled"); } else { task.PostResult(AccessToken.CurrentAccessToken); } }); }); return(task); }