Exemplo n.º 1
0
        private void FacebookPost(Account facebookAccount, string message, string clientID, string link)
        {
            var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?"), null, facebookAccount);
            request.GetResponseAsync().ContinueWith(t =>
                {
                    InvokeOnMainThread(() =>
                    {
                        if (t.IsFaulted)
                        {
                            FacebookLoginPost(clientID, message, link);
                        }
                        else
                        {
                            // 1. Create the service
                            var facebook = new FacebookService
                            {
                                ClientId = clientID,
                            };

                            facebook.SaveAccount(facebookAccount);

                            // 2. Create an item to share
                            var item = new Item();
                            item.Text = message;
                            if (!String.IsNullOrEmpty(link) )
                            {
                                item.Links.Add(new Uri(link));
                            }

                            // 3. Present the UI on iOS
                            UIViewController cur_ViewController=(auth_ViewController==null?c_ViewController:auth_ViewController);
                            var shareController = facebook.GetShareUI(item, result =>
                            {
                                            new UIAlertView ("Result",result.ToString(), null, "Ok").Show ();
                                            c_ViewController.DismissViewController(true,null);
                            });
                                    cur_ViewController.PresentViewController(shareController, true, null);
                        }
                    });
                });
        }
Exemplo n.º 2
0
        private void FacebookPost(Account facebookAccount, string message, string clientID, string link)
        {
            var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, facebookAccount);
            request.GetResponseAsync().ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        Console.WriteLine("Error: " + t.Exception.InnerException.Message);
                        FacebookLoginPost(clientID, message, link);
                    }
                    else
                    {
                        // 1. Create the service
                        var facebook = new FacebookService { ClientId = clientID };

                        facebook.SaveAccount(Forms.Context, facebookAccount);

                        // 2. Create an item to share
                        var item = new Item();
                        item.Text = message;
                        if (link != null)
                        {
                            item.Links.Add(new Uri(link));
                        }
                        Device.BeginInvokeOnMainThread(() =>
                            {
                                // 3. Present the UI on iOS
                                var shareIntent = facebook.GetShareUI((Activity)Forms.Context, item, result =>
                                    {
                                        // result lets you know if the user shared the item or canceled
                                    });
                                Forms.Context.StartActivity(shareIntent);
                            });
                    }
                });
        }
Exemplo n.º 3
0
        private void FacebookPost(Account facebookAccount, string message, string clientID, string link)
        {
            var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, facebookAccount);
            request.GetResponseAsync().ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        Console.WriteLine("Error: " + t.Exception.InnerException.Message);
                        FacebookLoginPost(clientID, message, link);
                    }
                    else
                    {
                        // 1. Create the service
                        var facebook = new FacebookService
                        {
                            ClientId = clientID,
                        };

                        facebook.SaveAccount(facebookAccount);

                        // 2. Create an item to share
                        var item = new Item();
                        item.Text = message;
                        if (link != null)
                        {
                            item.Links.Add(new Uri(link));
                        }

                        // 3. Present the UI on iOS
                        InvokeOnMainThread(() =>
                            {
                                var shareController = facebook.GetShareUI(item, result =>
                                    {
                                        UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null);
                                    });
                                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(shareController, true, null);
                            });
                    }
                });
        }