开发者

Something wrong with passing parameter to FB Api() method

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",
开发者_C百科         "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!


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜