在C#中登录FaceBook Connect后如何获取用户名 [英] how to get the username after login FaceBook Connect in C#

查看:237
本文介绍了在C#中登录FaceBook Connect后如何获取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi专家,

我正在使用C#创建一个asp.net应用程序,并希望实现该
用户将使用Facebook Crenditial登录到我的网站,并且一旦登录,他的信息就会存储到Membership(ASpnetdb)数据库中

请帮我迫切

hi Experts,

I am creating an asp.net Application using C# and Want to Implement that the
user will Login using Facebook Crenditial to My site and And As soon as he Login his Information Will Get Stored Into Membership(ASpnetdb)database

Please Help Me Out Its Urgent

推荐答案

我要使用我的Facebook凭据登录到您的网站吗?

否.出于某些原因,我认为我不会.

为什么不是呢?我听到你问.

因为我不希望我的登录详细信息存储在您的数据库中.或任何您可以找到他们的地方.

请参见此处 [
Would I log into your site using my Facebook credentials?

No. For some reason I don''t think I would.

Why on earth not? I hear you ask.

Because I don''t want my login details stored on your database. Or anywhere you can get at them.

See here[^] for how facebook authentication works.


如果您使用的是Facebook graph API,则登录用户的显示名称将作为 Name 属性/字段(无论您想要什么)返回称呼它).这是我几个月前工作的一个测试项目的一些示例代码(用于WP7,但是概念也应该与ASP.NET非常相似).请注意,我是如何仅解析选择字段/属性的(当然还有更多).

If you are using the Facebook graph API, then the display name of the logged in user is returned as the Name property/field (whatever you want to call it). Here''s some sample code from a test project I worked on a couple of months ago (it''s for WP7, but the concepts should be very similar from ASP.NET too). Note how I only parse out select fields/properties (there are several more of course).

[DataContract]
public class FBUser
{
    [DataMember(Name = "name")]
    public string Name { get; set; }

    [DataMember(Name = "gender")]
    public string Gender { get; set; }

    [DataMember(Name = "id")]
    public string Id { get; set; }
}

void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(FBUser));
    using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(e.Result)))
    {
        var tmp = serializer.ReadObject(ms);
        FBUser user = tmp as FBUser;
        if (user != null)
        {
            textBox.Text = String.Format("{0} ({1})", user.Name, user.Gender);
        }
    }
}


这篇关于在C#中登录FaceBook Connect后如何获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆