Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

profile picture for facebook in xamarin.forms

$
0
0

im very interested in connecting an image and label via binding from the graph.facebook.api for the users profile pic/name...... now doing this via xamarin.forms is the real tricky part
// this is just the import part of eventshippage.xaml

        <Label Text="{Binding}" xName="profilename" />
            <Image Source="{binding}" x:Name="profilepic"/>

so on a master menu details page i have these two controls/elements
both have a name so i can reference them. the tricky part isnt the bindingcontext but
finding out how to make the right calls.

i followed an example of how to setup the login i think from AWS cognito cause im using their login features and did my research and found out i could

        LoginManager.getInstance().logInWithReadPermissions(signInActivity,
            Arrays.asList("public_profile", "email")); 

what does any of this means i dont know cause ive been searching for documentation EVERYWHERE!!!! but ill give you a taste of my customfacebookbutton renderer

                    using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;

        using Foundation;
        using UIKit;
        using Xamarin.Forms;
        using Xamarin.Forms.Platform.iOS;
        using EventShip;
        using EventShip.iOS;
        using Facebook.LoginKit;

        [assembly: ExportRenderer(typeof(FacebookLoginButton), typeof(FacebookLoginButtonRenderer))]
        namespace EventShip.iOS
        {
            class FacebookLoginButtonRenderer:ButtonRenderer
            {
                protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
                {
                    base.OnElementChanged(e);
                    if (Control != null)
                    {
                        UIButton button = Control;

                        button.TouchUpInside += delegate
                        {
                            HandleFacebookLoginClicked();
                        };
                    }
                }
                List<string> readPermissions = new List<string> { "public_profile" };

                private void HandleFacebookLoginClicked()
                {
                    LoginManager login = new LoginManager();
                    login.LogInWithReadPermissions(readPermissions.ToArray(), delegate(LoginManagerLoginResult result, NSError error)
                    {
                        if (error != null)
                        {
                            App.OnFacebookAuthFailed();
                        }
                        else if (result.IsCancelled)
                        {
                            App.OnFacebookAuthFailed();
                        }
                        else
                        {
                            var accessToken = result.Token;
                            App.OnFacebookAuthSuccess(accessToken.TokenString);
                        }
                    });
                }


            }
        }

so far i think ive understood that its in the custom renderer we want to do all the loggining and graph api calls though delegates. so in my app.cs ive got three delegates

                using System;
    using Xamarin.Forms;

    namespace EventShip
    {
        public partial class App : Application
        {
            public App()
            {
                InitializeComponent();
                //******* This Activates the Master Detail Page, by building a new navigation page and then sendng the menuepagemaster to it 
                MainPage = new NavigationPage(new MenuPageMaster());

            }
            public static Action<string> OnFacebookAuthSuccess;
            // this one was made by me to try and only send the string url to the image binding but i couldnt figure out how
            public static Action<string> UrlProfileImage;
            public static Action OnFacebookAuthFailed;

            public void UpdateMainPage(ContentPage page)
            {
                MainPage = new NavigationPage(page);
                //MainPage = NavPage;
            }

            protected override void OnStart()
            {
                // Handle when your app starts
            }

        }
    }


and this is where i want the info loading into  but i dont know how im lost without any examples of code or clear documentation on neither xamarin.facebook or aws 




        using System;
        using System.Collections.Generic;

        using Xamarin.Forms;

        namespace EventShip
        {
            public partial class FacebookMasterPage : MasterDetailPage
            {

                public FacebookMasterPage()
                {
                    //profilepic.BindingContext;
                    InitializeComponent();
                    LoginManager.getInstance().logInWithReadPermissions(signInActivity,
                       Arrays.asList("public_profile", "email"));
                    this.Detail = new EventShipPage();


                }

                public void LoginButton_Clicked(object sender, EventArgs e)
                {
                    this.Detail = new LoginPage();
                    this.IsPresented = false;
                }










            }










        }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>