将参数传递给 FB Api() 方法时出现问题

发布于 2024-10-10 21:55:21 字数 1608 浏览 3 评论 0原文

我有以下代码来获取我的朋友列表,并返回一些特定字段。

public ActionResult Test()
{
    fbApp = new FacebookApp();
    authorizer = new CanvasAuthorizer(fbApp);
    authorizer.Perms = requiredAppPermissions;

    if (fbApp.Session != null)
    {
        dynamic friendsFields = new ExpandoObject();
        friendsFields.fields = "id,name,location,bio,gender,religion,activities";
        JsonObject data = fbApp.Get("/me/friends", friendsFields);

        ViewData["friends"] = data["data"] as JsonArray;

        return View();
    }
}

我要求提供 id、姓名、位置、个人简介、性别、宗教、活动字段,但结果并未提交所有这些字段。仅返回 id、name、gender,这让人怀疑有什么问题......如果我尝试使用浏览器获取相同的数据并传递字段,结果将返回所有请求的字段:

URL: https://graph.facebook.com/me/friends?fields=id,name,bio,gender,picture,religion,activities&access_token=...
   "data": [
      {
         "id": "data_data_data",
         "name": "data_data_data",
         "bio": "data_data_data",
         "gender": "data_data_data",
         "religion": "data_data_data",
         "picture": "data_data_data",
         "activities": {
            "data": [
               {
                  "name": "data_data_data",
                  "category": "data_data_data",
                  "id": "data_data_data",
                  "created_time": "data_data_data"
               }
            ]
         }
      },
      {
         "id": "data_data_data",
         "name": "data_data_data",
         "bio": "data_data_data",
         "gender": "data_data_data",
         "picture": "data_data_data"
      }
   ]
}

有人知道这里可能出了什么问题吗?可以是API吗?我使用的是最新版本4.1.1

TIA!

I've the following code that fetches my friends list with some specific fields to be returned.

public ActionResult Test()
{
    fbApp = new FacebookApp();
    authorizer = new CanvasAuthorizer(fbApp);
    authorizer.Perms = requiredAppPermissions;

    if (fbApp.Session != null)
    {
        dynamic friendsFields = new ExpandoObject();
        friendsFields.fields = "id,name,location,bio,gender,religion,activities";
        JsonObject data = fbApp.Get("/me/friends", friendsFields);

        ViewData["friends"] = data["data"] as JsonArray;

        return View();
    }
}

I'm asking for id,name,location,bio,gender,religion,activities fields, but the result doesn't submit all those fields. Only id,name,gender are returned which makes suspect something is wrong... if i try to get the same data using the browser and passing the fields the result returns all the requested fields:

URL: https://graph.facebook.com/me/friends?fields=id,name,bio,gender,picture,religion,activities&access_token=...
   "data": [
      {
         "id": "data_data_data",
         "name": "data_data_data",
         "bio": "data_data_data",
         "gender": "data_data_data",
         "religion": "data_data_data",
         "picture": "data_data_data",
         "activities": {
            "data": [
               {
                  "name": "data_data_data",
                  "category": "data_data_data",
                  "id": "data_data_data",
                  "created_time": "data_data_data"
               }
            ]
         }
      },
      {
         "id": "data_data_data",
         "name": "data_data_data",
         "bio": "data_data_data",
         "gender": "data_data_data",
         "picture": "data_data_data"
      }
   ]
}

Anyone have any idea what might be wrong here? Can it be the API? I'm using the latest version 4.1.1

TIA!

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

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

发布评论

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

评论(1

相权↑美人 2024-10-17 21:55:21

您必须强制转换 Get 方法的结果或仅动态访问它。这是更正后的代码,也修复了授权。

[CanvasAuthorize(Perms="user_friends")]
public ActionResult Test()
{
    var fbApp = new FacebookApp();  
    dynamic friendsFields = new ExpandoObject();
    friendsFields.fields = "id,name,location,bio,gender,religion,activities";
    dynamic result = fbApp.Get("/me/friends", friendsFields);

    var data = result.data as JsonArray;
    ViewData["friends"] = data;

    return View();
}

You have to cast the result of the Get method or just access it dynamically. Here is the corrected code with the authorization fixed as well.

[CanvasAuthorize(Perms="user_friends")]
public ActionResult Test()
{
    var fbApp = new FacebookApp();  
    dynamic friendsFields = new ExpandoObject();
    friendsFields.fields = "id,name,location,bio,gender,religion,activities";
    dynamic result = fbApp.Get("/me/friends", friendsFields);

    var data = result.data as JsonArray;
    ViewData["friends"] = data;

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