Пример #1
0
        private void InitializeComponents()
        {
            try
            {
                progress_bar = FindViewById <ProgressBar>(Resource.Id.progress_bar_login);

                btn_login_facebook = FindViewById <Button>(Resource.Id.btn_login_facebook);

                btn_login_facebook.SetOnClickListener(this);

                FacebookSdk.SdkInitialize(ApplicationContext);

                callbackManager = CallbackManagerFactory.Create();

                graphCallback = new GraphJSONObjectCallback
                {
                    HandleSuccess = email =>
                    {
                        LoginWithFacebook(Profile.CurrentProfile, email);
                    }
                };

                loginCallback = new FacebookCallback <LoginResult>
                {
                    HandleSuccess = loginResult =>
                    {
                        var request = GraphRequest.NewMeRequest(loginResult.AccessToken, graphCallback);

                        Bundle parameters = new Bundle();

                        parameters.PutString("fields", "id, name, email");

                        request.Parameters = parameters;

                        request.ExecuteAsync();
                    },
                    HandleCancel = () =>
                    {
                        StopLoading();
                    },
                    HandleError = loginError =>
                    {
                        StopLoading();
                    }
                };

                Xamarin.Facebook.Login.LoginManager.Instance.RegisterCallback(callbackManager, loginCallback);

                CheckUserLogged();
            }
            catch (Exception exception)
            {
                InsightsUtils.LogException(exception);
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Initialize the SDK before executing any other operations
            FacebookSdk.SdkInitialize(Application.Context);

            // create callback manager using CallbackManagerFactory
            callbackManager = CallbackManagerFactory.Create();

            LoginManager.Instance.RegisterCallback(callbackManager, new MyFacebookCallback <LoginResult>(this));

            shareDialog   = new ShareDialog(this);
            shareCallback = new MySharedDialogCallback <SharerResult>(this);
            shareDialog.RegisterCallback(callbackManager, shareCallback);

            if (savedInstanceState != null)
            {
                var name = savedInstanceState.GetString(PENDING_ACTION_BUNDLE_KEY);
                System.Enum.TryParse(name, true, out pendingAction);
            }

            SetContentView(Resource.Layout.main);

            profileTracker = new MyProfileTracker(this);

            profilePictureView = FindViewById <ProfilePictureView>(Resource.Id.profilePicture);
            greeting           = FindViewById <TextView>(Resource.Id.greeting);

            postStatusUpdateButton        = FindViewById <Button>(Resource.Id.postStatusUpdateButton);
            postStatusUpdateButton.Click += (sender, args) =>
            {
                OnClickPostStatusUpdate();
            };

            postPhotoButton        = FindViewById <Button>(Resource.Id.postPhotoButton);
            postPhotoButton.Click += (sender, args) =>
            {
                OnClickPostPhoto();
            };

            // Can we present the share dialog for regular links?
            canPresentShareDialog = ShareDialog.CanShow(Class.FromType(typeof(ShareLinkContent)));

            // Can we present the share dialog for photos?
            canPresentShareDialogWithPhotos = ShareDialog.CanShow(Class.FromType(typeof(SharePhotoContent)));
        }