Answered by:
Facebook Connect - user info issue

Question
-
User1904457954 posted
Hi
I am having issues on face book connect. It works fine in my testing url. But does not work in real website. Same code, I am not able to find out any issue.
Only the difference is i am using master page and ASP.net 3.5 in real website. The testing URL works fine : http://www.evisioning.com/ksh_test.
I am using FaceBook.dll version 3.0.0
Here is code
-------------------------------------------------
Master Page
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Home.master.cs" Inherits="CityBucks.Home" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head runat="server">
<title>City Buck$</title>
</head>
<body runat="server" >
<form id="frmHome" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<table id="Table1" width="100%" runat="server" border="0" cellpadding="0" cellspacing="0" bordercolor="red" >
<tr>
<td colspan="2" valign="top">
<asp:Label ID="lblUser" CssClass="horizonatal-title" runat="server" Text="" ></asp:Label>
<fb:login-button length="small" onlogin='FB.Connect.showPermissionDialog("email,read_stream", function(x){window.location.reload();});'></fb:login-button>
<asp:Image ID="imgUserLoggedIn" Visible="false" Height="23px" Width="27px" runat="server"
ImageUrl="~/Images/robert.jpg" ></asp:Image>
</td>
</tr>
</table>
</form>
<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>
<script type="text/javascript">
FB.init("7848902f786790ba095717803fc466a4", "xd_receiver.htm");
</script>
</body>
</html>
Master Page Code Behind
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using Facebook.Rest;
using Facebook.Session;
using Facebook.Schema;
using System.Collections.Generic;
using System.Xml;
namespace CityBucks
{
public partial class Home : System.Web.UI.MasterPage
{
protected string logedin = "N";
protected string iimage = "";
protected string bannerstyle = "";
protected string cid = "";
protected string UserID = "0";
public Facebook.Rest.Api Api;
public Facebook.Session.ConnectSession connectSession;
public ConnectSession CurrentSession
{
get
{
ConnectSession connectSession = new ConnectSession(clsFBConnect.ApiKey, clsFBConnect.SecretKey);
return connectSession;
}
}
protected void Page_Init(object s, EventArgs e)
{
try
{
if (clsFBConnect.isConnected())
{
Api api = new Api(CurrentSession);
this.imgUserLoggedIn.Visible = true;
this.lblUser.Visible = true;
Facebook.Schema.user user = api.Users.GetInfo();
string fullName = user.first_name + " " + user.last_name;
this.lblUser.Text = fullName;
this.imgUserLoggedIn.ImageUrl = user.pic_square;
if (api.Users.HasAppPermission(Facebook.Schema.Enums.ExtendedPermissions.email))
{
string result = api.Fql.Query("SELECT email FROM user WHERE uid=" + user.uid.ToString());
XmlDocument x = new XmlDocument();
x.LoadXml(result);
XmlNode email_xml = x.GetElementsByTagName("email").Item(0);
Response.Write(email_xml.InnerText);
}
}
else
{
}
}
catch (Exception Ex)
{
Response.Write(Ex.InnerException.ToString());
}
}
}
}
--------------------------------fbConnect.cs---------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
/// <summary>
/// Summary description for ConnectAuthentication
/// </summary>
public class clsFBConnect
{
public clsFBConnect()
{
}
public static bool isConnected()
{
return (SessionKey != null && UserID != -1);
}
public static string ApiKey
{
get
{
return ConfigurationManager.AppSettings["API_KEY"];
}
}
public static string SecretKey
{
get
{
return ConfigurationManager.AppSettings["SECRET_KEY"];
}
}
public static string SessionKey
{
get
{
return GetFacebookCookie("session_key");
}
}
public static int UserID
{
get
{
int userID = -1;
int.TryParse(GetFacebookCookie("user"), out userID);
return userID;
}
}
private static string GetFacebookCookie(string cookieName)
{
string retString = null;
string fullCookie = ApiKey + "_" + cookieName;
if (HttpContext.Current.Request.Cookies[fullCookie] != null)
retString = HttpContext.Current.Request.Cookies[fullCookie].Value;
return retString;
}
}
------Facebook.dll v.3.0.0-,Facebook.Web.dll Ver 3.0.0---
Tuesday, September 28, 2010 1:48 PM
Answers
-
User1904457954 posted
Resloved :
I put APPKEY and SECRET KEY not in appsettin in web.config
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 29, 2010 3:10 PM