0

I am trying to fetch Facebook profile data through Graph API. I am using Facebook SDK in MVC application. Using the following code returns dynamic result.

dynamic myInfo = await fb.GetTaskAsync("v2.8/me?fields=first_name,last_name,link,locale,email,name,birthday,gender,location,age_range");
      var facebookProfile = new FacebookProfileViewModel()
                {
                    FirstName = myInfo.first_name,
                    LastName = myInfo.last_name,
                    LinkUrl = myInfo.link,
                    Locale = myInfo.locale };

I am getting the data from facebook like this -

[{"Key":"first_name","Value":"John"},{"Key":"last_name","Value":"Doe"},{"Key":"link","Value":"https://www.facebook.com/app_scoped_user_id/4327693/"}]

I am getting the following error -

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot implicitly convert type 'Facebook.JsonObject' to 'string'
Tajuddin
  • 73
  • 3
  • 13

1 Answers1

1

Install newtonsoft:

Install-Package Newtonsoft.Json

Convert from json:

string json = 
"[
    {
        "Key": "first_name",
        "Value": "John"
    },
    {
        "Key": "last_name",
        "Value": "Doe"
    },
    {
        "Key": "link",
        "Value": "https://www.facebook.com/app_scoped_user_id/4327693/"
    }
]";
FbProfile Profile = JsonConvert.DeserializeObject<FbProfile>(json);
Community
  • 1
  • 1
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • Thank you Mohit. It does not work, I have tried to bind with my ViewModel. – Tajuddin Nov 30 '16 at 08:48
  • not work because Expected json result {"first_name":"John","last_name":"Doe","link":"https://www.facebook.com/app_scoped_user_id/4327693/"} – go.. Nov 30 '16 at 08:49
  • @snnbrn this is also a valid json. Lemme format it to show how it looks like – Mohit S Nov 30 '16 at 08:51