我有奇怪的事情,当我点击 Facebook 选项卡来玩我的游戏时,身份验证消息没有出现,但我必须复制我将游戏放在我们的服务器上的游戏 URL,并且身份验证消息出现并且可以在我点击时进行身份验证Facebook标签它运作良好。那么有什么问题呢?
Facebook_登录页面
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string host = System.Configuration.ConfigurationManager.AppSettings["host"];
string facebookClientId =
System.Configuration.ConfigurationManager.AppSettings["FacebookClientId"];
string RedirectURL = "http://facebookapp.elarabygroup.com";
if (Request.QueryString["redirectURL"] != null)
{
RedirectURL = Request.QueryString["redirectURL"].ToString();
Session["RedirectURL"] = RedirectURL;
}
Response.Redirect(@"https://graph.facebook.com/oauth/authorize?client_id=" +
facebookClientId + "&redirect_uri=http://" + host +
@"/FBcallback.aspx&scope=publish_stream,offline_access,publish_actions");
}
}
FB回调页面
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["code"] != null)
{
string facebookClientId = System.Configuration.ConfigurationManager.AppSettings["FacebookClientId"];
string facebookSecret = System.Configuration.ConfigurationManager.AppSettings["FacebookSecret"];
string host = System.Configuration.ConfigurationManager.AppSettings["host"];
string code = Request.QueryString["code"];
var url =
string.Concat("https://graph.facebook.com/oauth/access_token?client_id=" + facebookClientId,"&redirect_uri=http://" + host + "/admin/facebook/auth.aspx","&client_secret=" + facebookSecret,"&code=" + code);
oAuthFacebooks fbAC = new oAuthFacebooks();
string respnse = "";
try
{
fbAC.AccessTokenGet(code);
respnse = fbAC.Token;
}
catch (Exception ex)
{
Response.Redirect("http://x/SiteLogin.aspx?error=" + ex.Message);
}
if (Session["RedirectURL"] != null && Session["RedirectURL"].ToString() != "")
{
Response.Redirect(Session["RedirectURL"].ToString() + "?token=" + respnse + "&source=FB");
}
else
{
Response.Redirect("http://x/SiteLogin.aspx?token=" + respnse);
}
}
else
{
Response.Redirect("http://x/SiteLogin.aspx?error=code not found" +
Request.QueryString["error_reason"].ToString());
}
}
网站登录页面
if (Request.QueryString["token"] != null)
{
string token = Request.QueryString["token"];
string PostURL = string.Format("https://graph.facebook.com/me?access_token={0}", token);
oAuthFacebooks objFbCall = new oAuthFacebooks();
string JSONInfo = objFbCall.WebRequest(oAuthFacebooks.Method.GET, PostURL, "");
JObject Job = JObject.Parse(JSONInfo);
JToken Jdata = Job.Root;
//added from other soluation
// string code = Request.QueryString["code"];
if (Jdata.HasValues)
{
//added from other soluation
/*string data = FaceBookConnect.Fetch(code, "me");
FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);*/
string UID = (string)Jdata.SelectToken("id");
string firstname = (string)Jdata.SelectToken("first_name");
string lastname = (string)Jdata.SelectToken("last_name");
string pic = string.Format("https://graph.facebook.com/{0}/picture", UID);
string username = firstname + " " + lastname;
userdata.Attributes.Add("Value", "fb_id="+UID+ "&fb_name="+username+"&fb_img=" + pic);
userdata2.Attributes.Add("Value", "fb_id=" + UID + "&fb_name=" + username + "&fb_img=" + pic);
}
}
else
{ Response.Write(" xx"); }
}