locked
Set text of TextBox coming from Facebook API

    Question

  • I developing an app in which I need to set some data of user from facebook. So using WebAuthentication broker I get the user to login and then fetch the information and set it to the textbox values. The information is fetched properly but the values are not set in Textbox. I can't figure out the reason. Can somebody help? This is my function for setting the data.

    async public void SignUpUsingFacebook(string response)
            {            
                if (Utility.isInternetAvailable())
                {
                    try { MainPage.StartAnimation();
                    MainPage.loaderGrid.Visibility = Visibility.Visible;
                    }
                    catch
                    {
                        setAnimation();
                        StartAnimation();
                        loaderGrid.Visibility = Visibility.Visible;
                    }
                    string token = response.Substring(response.IndexOf('=') + 1);
                    string fbGetInfo = "https://graph.facebook.com/me?access_token=" + token;
                    HttpResponseMessage msg = await new HttpClient().GetAsync(new Uri(fbGetInfo), HttpCompletionOption.ResponseContentRead);
                    if (msg.IsSuccessStatusCode)
                    {
                        try
                        {
                            string fbData = await msg.Content.ReadAsStringAsync();
                            JObject j = JObject.Parse(fbData);
                            string fbId = j["id"].ToString();
                            txt_user_Name.Text = fbId;
                            txt_user_Name.Visibility = Visibility.Collapsed;
                            txt_first_Name.Text = j["first_name"].ToString();
                            txt_last_Name.Text = j["last_name"].ToString();
                            txt_email_Address.Text = j["email"].ToString();
                            txt_retype_email_Address.Text = j["email"].ToString();
                            gender = j["gender"].ToString();
                            if (gender.Equals("male", StringComparison.OrdinalIgnoreCase) || gender.Equals("boy", StringComparison.OrdinalIgnoreCase))
                            {
                                boy.Visibility = Visibility.Collapsed;
                                boySelected.Visibility = Visibility.Visible;
                                girlSelected.Visibility = Visibility.Collapsed;
                                girl.Visibility = Visibility.Visible;
                            }
                            else if (gender.Equals("female", StringComparison.OrdinalIgnoreCase) || gender.Equals("girl", StringComparison.OrdinalIgnoreCase))
                            {
                                girlSelected.Visibility = Visibility.Visible;
                                boySelected.Visibility = Visibility.Collapsed;
                                girl.Visibility = Visibility.Collapsed;
                                boy.Visibility = Visibility.Visible;
                            }
                        }
                        catch { }
                        try { MainPage.loaderGrid.Visibility = Visibility.Collapsed;
                        MainPage.StopAnimation();
                        }
                        catch
                        {
                            loaderGrid.Visibility = Visibility.Collapsed;
                            StopAnimation();
                        }
                    }
                    else
                    {
                        Utility.notifyUser("Your information from facebook could not be fetched", "");
                    }
                }
                else
                {
                    Utility.showMessage(Utility.msgType.InternetError);
                }
            }


    Monday, February 23, 2015 9:30 AM

Answers

  • The WebAuthenticationBroker has nothing to do with the issue of your textboxes not showing the values they were set to show.

    You are basically just setting string values to textboxes on your page. This shouldn't fail unless you are doing something else that is invalidating the values. Are you setting the values on a different page and viewing the changes on another?


    Abdulwahab Suleiman

    • Marked as answer by RohitrkKUmar Thursday, May 21, 2015 4:46 AM
    Thursday, February 26, 2015 4:42 PM
    Moderator

All replies

  • I would recommend setting a break-point after reading the json object. Then you can step through the code line-by-line checking to make sure the TextBox.Text contains a value after setting the value.

    Abdulwahab Suleiman

    Monday, February 23, 2015 6:21 PM
    Moderator
  • I did this and while debugging value is assigned but not shown in textbox
    Tuesday, February 24, 2015 4:13 AM
  • It's most likely that something in your project is overriding your changes. I would recommend testing with a plain app that has a few textboxes and your json data.

    Then you can go back to your main application and find out what extract code you are running that might be overriding your changes.


    Abdulwahab Suleiman

    Wednesday, February 25, 2015 3:03 AM
    Moderator
  • I did this and this error occurs when this method is called after the Webauthentication broker returns. It does not set the values. The same function works if I use a webview instead of WebAuthenticationBroker. I could not find the reason for this.
    Thursday, February 26, 2015 4:39 AM
  • The WebAuthenticationBroker has nothing to do with the issue of your textboxes not showing the values they were set to show.

    You are basically just setting string values to textboxes on your page. This shouldn't fail unless you are doing something else that is invalidating the values. Are you setting the values on a different page and viewing the changes on another?


    Abdulwahab Suleiman

    • Marked as answer by RohitrkKUmar Thursday, May 21, 2015 4:46 AM
    Thursday, February 26, 2015 4:42 PM
    Moderator
  • I got it as I had app structure and to compensate for this I was creating new object which was not allowing me to pass data.
    Friday, February 27, 2015 5:01 AM