Пример #1
0
        public static async Task<string> LogIn()
        {
            string message = String.Empty;
            try
            {
                FacebookSession session = new FacebookSession();
                FacebookSessionClient client = new FacebookSessionClient(App.fbAppID);
                session = await client.LoginAsync(
                    "user_about_me," +
                    "friends_about_me," +
                    "publish_stream");
                App.isAuthenticated = true;
                App.fbToken = session.AccessToken;
                App.fbUserID = session.FacebookId;

                 FacebookUser user = await Users.DownloadUserInfo(App.fbUserID);

                App.fbProfilePicture = user.Picture.data.url;
                App.fbProfileName = user.Name;
                return "OK";

            }
            catch (InvalidOperationException e)
            {
                message = "Login failed! Exception details: " + e.Message;
                return message;
            }
        }
        private async Task Authenticate()
        {
            ShowProgressBar(true);

            FacebookSession session;
            FacebookSessionClient fbclient = new FacebookSessionClient(FacebookAccount.App_Id);

            try
            {
                FacebookAccount.IsAuthenticated = true;

                session = await fbclient.LoginAsync(FacebookAccount.ExtendedPermissions);

                FacebookAccount.AccessToken = session.AccessToken;
                FacebookAccount.FacebookId = session.FacebookId;

                FacebookAccount.IsConnected = true;

                NavigationService.Navigate(new Uri("/Views/Birthdays.xaml", UriKind.RelativeOrAbsolute));
            }
            catch (InvalidOperationException ioe)
            {
                MessageBox.Show("Login Failed! Exception: " + ioe.Message);
            }
            finally
            {
                ShowProgressBar(false);
            }
        }
        public async Task<SocialResponse<UserInfo>> SignIn()
        {
            SocialResponse<UserInfo> result = new SocialResponse<UserInfo>();

            try
            {
                var facebookClient = new FacebookSessionClient(APP_ID);
                var session = await facebookClient.LoginAsync();

                if (!string.IsNullOrEmpty(session.AccessToken))
                {
                    result.Result = true;
                    settings.Set(FACEBOOK_TOKEN_SETTING, session.AccessToken);
                    settings.Set(FACEBOOK_TOKEN_EXPIRES_AT_SETTING, session.Expires.ToFileTimeUtc());
                    var userInfo = await GetUserInfo();
                    await GetExtendedToken();
                }
                Debug.WriteLine(session.AccessToken);
                Debug.WriteLine(session.FacebookId);
                Debug.WriteLine(session.Expires);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                result.Result = false;
            }
            return result;
        }
 private async Task GetFBLoginPage()
 {
     try
     {
         FacebookSessionClient facebookSessionClient = new  FacebookSessionClient("1218463084847397");
         FacebookSession session;
         session = await facebookSessionClient.LoginAsync("user_about_me");
         PurposeColor.App.SaveToken(session.AccessToken);
         PurposeColor.App.SuccessfulLoginAction();
     }
     catch (Exception ex)
     {
         Console.WriteLine("GetFBLoginPage : " + ex.Message);
     }
 }