使用Facebook SDK从C#MVC获取Facebook的用户详细信息 [英] Get User details from Facebook in C# MVC using Facebook SDK

查看:105
本文介绍了使用Facebook SDK从C#MVC获取Facebook的用户详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我真的需要一些紧急的帮助。我想在C#MVC中从Facebook获取新的用户详细信息。我在Visual Studio中下载了NuGet包,并将下面的代码放在我的控制器中。



我的问题是:



1.如何在C#中获取代码(访问令牌) ?有没有办法生成一个?我看到的所有示例都没有提到你是如何得到它的,但它们只是将代码显示为方法中的参数。



2.为了测试,我创建了一个Facebook网站上的访问令牌,以查看用户详细信息是否正确。我这样做时出错,说无效的网址。我搜索谷歌,我看到它是因为localhost网址,有没有人知道这方面的方法?



感谢所有的帮助。



Hi,

I am really in need of some urgent help please. I am trying to get a new users details from Facebook in C# MVC. I downloaded the NuGet package in Visual Studio and put the code below in my controller.

My questions are:

1. How would I get the code(access token) in C#? Is there a way I can generate one? All the examples I see don't mention how you get it but they just show the code as a parameter in the method.

2. For testing, I created an access token on the Facebook website to see if the user details comes through correctly. I get an error doing this, saying the invalid URL. I searched on Google and I see its because of the localhost url, does anyone know a way around this?

Thanks For all the help.

public ActionResult FacebookCallback(string EmailAddress, string Password, string code)
       {

           var fb = new FacebookClient();

           dynamic result = fb.Post("oauth/access_token", new
           {
               client_id = "XXXXXXXXXXX",
               client_secret = "YYYYYYYYYYYYYYYYYYY",
               redirect_uri = "http%3a%2f%2flocalhost%3a43568%2fRegister",
               code = <big>code</big>
           });

           var accessToken = result.access_token;

           // Store the access token in the session for farther use
           Session["AccessToken"] = accessToken;

           // update the facebook client with the access token so
           // we can make requests on behalf of the user
           fb.AccessToken = accessToken;

           // Get the user's information, like email, first name, middle name etc
           dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email");
           string email = me.email;
           string firstname = me.first_name;
           string middlename = me.middle_name;
           string lastname = me.last_name;

           // Set the auth cookie
           FormsAuthentication.SetAuthCookie(email, false);
           return RedirectToAction("Index", "Home");
       }

推荐答案

在ASP.NET和C#中获取用户Facebook详细信息 [ ^ ]>



http://stackoverflow.com/questions/22936240/how-to -access-the-users-email-id-with-asp-net-mvc-facebook [ ^ ]>



请查看上面的链接
Get user Facebook details in ASP.NET and C#[^]>

http://stackoverflow.com/questions/22936240/how-to-access-the-users-email-id-with-asp-net-mvc-facebook[^]>

Check the links above please


这篇关于使用Facebook SDK从C#MVC获取Facebook的用户详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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