首页 文章

如何使用xamarin.auth从facebook检索配置文件信息

提问于
浏览
0

我正在Xamarin.Forms中编写一个简单的应用程序,允许用户通过社交网站进行身份验证,例如Facebook,Google,Instagram,Twitter等 . 我正在使用Xamarin.auth来执行此操作 . Facebook登录时遇到问题 . 我使用了官方指南中报告的相同代码:

https://components.xamarin.com/gettingstarted/xamarin.auth

但是在应用程序请求用户提供凭据之后,响应(在代码中,t.Result.GetResponseText(),第3节)是一个json包含Facebook用户名和姓氏,以及一个名为“id”的字段 . 相反,我需要用户的所有 Profiles 信息,例如年龄,性别等 . 我想我必须使用返回的id来构建对facebook服务的http请求以从id中检索数据 .

1 回答

  • 2

    您需要在Facebook链接中指定所需的字段 .

    Example:

    var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=email,first_name,last_name,gender,picture"), null, eventArgs.Account);
    

    After how I Get the fields

    var response = await request.GetResponseAsync();
    var obj = JObject.Parse(response.GetResponseText());
    
    var id = obj["id"].ToString().Replace("\"", "");
    var name = obj["first_name"].ToString().Replace("\"", "");
    var lastName = obj["last_name"].ToString().Replace("\"", "");
    var email = obj["email"].ToString().Replace("\"", "");
    

相关问题