【问题标题】:How to retrieve profile informations from facebook using xamarin.auth如何使用 xamarin.auth 从 facebook 检索个人资料信息
【发布时间】:2016-09-29 06:50:37
【问题描述】:

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

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

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

【问题讨论】:

    标签: facebook authentication xamarin xamarin.auth


    【解决方案1】:

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

    示例:

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

    在我如何获取字段之后

    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("\"", "");
    

    【讨论】:

    • 为什么我会收到这个错误(在线 - var obj = JObject.Parse(response.GetResponseText()); ):Task 不包含 GetResponseText 的定义?
    • 因为也许你定义变量“response”就像一个 Task 并且 Task 不包含任何 GetReponseText 方法的定义,所以你需要定义一个像 Response 类型的“response”变量.
    猜你喜欢
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 2014-05-02
    • 2013-11-24
    • 2018-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多