Question

Just started today some dev using Facebook SDK and i can't figure out the logic followed to link the members of the expando object to the fields in the Graph API objects in the example bellow that was taken from facebook C# SDK docs:

   public ActionResult RestFacebookPage()
   {
      FacebookApp app = new FacebookApp();
      dynamic parameters = new ExpandoObject();
      parameters.page_ids = "85158793417";
      parameters.method = "pages.getInfo";
      parameters.fields = "name";
      dynamic result = app.Api(parameters);
      return View("FacebookPage", result);
   }

I do understand the page_ids and fields, but not pages.getInfo. It would be great if someone could enlighten me here and tell me where in the documentation i can find a reference that leads me to this....

Thanks a lot!

Was it helpful?

Solution

Not sure I understand what you are asking but there is a pretty decent example about translating php to facebook-c#-sdk over on their project page. Then you can just look up the official facebook developer documentation directly.

If you were asking more off a "how is this implemented" type of question, the best way to do this in my opinion is to break at the line containing app.Api and from there just step through the code. In the Api method there is a check to see if the parameters dictionary contains a key "method". If there is, the sdk figures the call is bound for the old rest api, not the graph api. A few stack frames lower we find the code that makes the url:


protected virtual Uri GetUrl(string name, string path, IDictionary parameters)
{
  Contract.Requires(!String.IsNullOrEmpty(name));
  Contract.Ensures(Contract.Result() != default(Uri));

  if (_domainMaps[name] == null)
  {
    throw new ArgumentException("Invalid url name.");
  }

  UriBuilder uri = new UriBuilder(_domainMaps[name]);
  if (!String.IsNullOrEmpty(path))
  {
    if (path[0] == '/')
    {
      if (path.Length > 1)
      {
        path = path.Substring(1);
      }
      else
      {
        path = string.Empty;
      }
    }
    if (!String.IsNullOrEmpty(path))
    {
      uri.Path = UriEncoder.EscapeDataString(path);
    }
  }
  if (parameters != null)
  {
    uri.Query = parameters.ToJsonQueryString();
  }
  return uri.Uri;
}

You should probably step into this method yourself to see what the variables hold and it should make sense to you. The source is always the best documentation. Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top