ExpandoObject() 成员和 FB Graph API 链接背后的逻辑

发布于 2024-10-07 16:50:25 字数 597 浏览 1 评论 0原文

今天刚开始使用 Facebook SDK 的一些开发人员,我无法弄清楚将 Expando 对象的成员链接到下面示例中的 Graph API 对象中的字段的逻辑,该示例取自 facebook C# SDK 文档:

   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);
   }

我确实明白page_ids 和字段,但不是pages.getInfo。如果有人能在这里启发我并告诉我在文档中的哪里可以找到引导我找到此内容的参考文献,那就太好了......

非常感谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

じее 2024-10-14 16:50:25

不确定我明白你在问什么,但在他们的 项目页面。那么你可以直接查找facebook官方开发者文档。

如果您想问更多“这是如何实现的”类型的问题,我认为最好的方法是在包含 app.Api 的行处进行中断,然后从那里单步执行代码。在 Api 方法中,会检查参数字典是否包含关键“方法”。如果有,sdk 会认为该调用是绑定到旧的 Rest api,而不是图 api。在下面的几个堆栈帧中,我们找到了生成 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;
}

您可能应该亲自进入此方法以查看变量保存的内容,并且它应该对您有意义。源码永远是最好的文档。希望这有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文