Facebook 与 Asp .Net 集成
我需要将 Facebook 与我的 asp .net 应用程序集成。以下是我为此遵循的步骤。
- 我已经从脸书创建了脸书应用程序并获得了应用程序密钥和密钥。
- 我已在我的应用程序中使用了该应用程序密钥和秘密密钥。
这是我的代码:
但在这段代码中,“Session[”facebook_userId”]”总是给我空值。你能告诉我原因吗?
protected void Page_Load(对象发送者,EventArgs e) {
_fbService.ApplicationKey = FACEBOOK_APPKEY;
_fbService.Secret = FACEBOOK_SECRET;
_fbService.IsDesktopApplication = false;
string sessionKey = Session["facebook_session_key"] as String;
userId = Session["facebook_userId"] as String;
// When the user uses the facebook login page,
// the redirect back here will have the auth_token in the query params
string authToken = Request.QueryString["auth_token"];
if (!String.IsNullOrEmpty(sessionKey))
{
_fbService.SessionKey = sessionKey;
_fbService.UserId = userId;
}
else if (!String.IsNullOrEmpty(authToken))
{
_fbService.CreateSession(authToken);
Session["facebook_session_key"] = _fbService.SessionKey;
Session["facebook_userId"] = _fbService.UserId;
Session["facebook_session_expires"] = _fbService.SessionExpires;
}
else
{
Response.Redirect(@"http://www.facebook.com/login.php?api_key=" +
_fbService.ApplicationKey + @"&v=1.0");
}
if (!IsPostBack)
{
System.Collections.ObjectModel.Collection<User> userinfo = _fbService.GetUserInfo(_fbService.UserId);
Label1.Text = userinfo[0].FirstName + "'s favorite shops";
Image1.ImageUrl = userinfo[0].PictureUrl.ToString();
// Use the FacebookService Component to populate Friends
System.Collections.ObjectModel.Collection<User> Friends = _fbService.GetFriends();
for (int i = 0; i < Friends.Count; i++)
DropDownList2.Items.Add(Friends[i].FirstName.ToString());
}
}
}
请帮我解决这个问题!
I need to integrate face book with my asp .net application. Here are the steps i have followed for it.
- I have created face-book application from face-book and got application key and secret key.
- I have used that application key and secret key in my application.
here is my code :
But in this code, "Session["facebook_userId"]" is always giving me null value. can you tell me the reason for this ?
protected void Page_Load(object sender, EventArgs e)
{
_fbService.ApplicationKey = FACEBOOK_APPKEY;
_fbService.Secret = FACEBOOK_SECRET;
_fbService.IsDesktopApplication = false;
string sessionKey = Session["facebook_session_key"] as String;
userId = Session["facebook_userId"] as String;
// When the user uses the facebook login page,
// the redirect back here will have the auth_token in the query params
string authToken = Request.QueryString["auth_token"];
if (!String.IsNullOrEmpty(sessionKey))
{
_fbService.SessionKey = sessionKey;
_fbService.UserId = userId;
}
else if (!String.IsNullOrEmpty(authToken))
{
_fbService.CreateSession(authToken);
Session["facebook_session_key"] = _fbService.SessionKey;
Session["facebook_userId"] = _fbService.UserId;
Session["facebook_session_expires"] = _fbService.SessionExpires;
}
else
{
Response.Redirect(@"http://www.facebook.com/login.php?api_key=" +
_fbService.ApplicationKey + @"&v=1.0");
}
if (!IsPostBack)
{
System.Collections.ObjectModel.Collection<User> userinfo = _fbService.GetUserInfo(_fbService.UserId);
Label1.Text = userinfo[0].FirstName + "'s favorite shops";
Image1.ImageUrl = userinfo[0].PictureUrl.ToString();
// Use the FacebookService Component to populate Friends
System.Collections.ObjectModel.Collection<User> Friends = _fbService.GetFriends();
for (int i = 0; i < Friends.Count; i++)
DropDownList2.Items.Add(Friends[i].FirstName.ToString());
}
}
}
Please help me for this !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你用的是哪个工具包??
我建议你使用 codeplex 的 facebooksdk 。是的,正如 Rufinus 所说,对于 Facebook 的每个请求,您都需要 access_token。我在代码中的任何位置都看不到它,
请点击此链接。C# 中的 Facebook Graph API
Which toolkit are you using ??
I suggest you use the facebooksdk from codeplex. And yes as Rufinus says, you will need the access_token for every request to facebook. I cannot see it anywhere in your code
Follow this link instead.. Facebook Graph API in C#