Facebook粉丝页面应用 [英] Facebook fan page app
问题描述
我已经使用C#SDK构建了一些Facebook应用程序.并使用下面的代码检查用户是否喜欢该粉丝页面并显示相应内容.
I've built a few facebook apps using the c# sdk. and using code below to check if the user has liked the fan page and showing content to reflect that.
protected void Page_Load(object sender, EventArgs e)
{
if (Session["SignedRequest"] != null)
{
signedRequest = Session["SignedRequest"].ToString();
}
else
{
signedRequest = Request.Form["signed_request"];
}
if (!string.IsNullOrEmpty(signedRequest))
{
dynamic SignedRequestData;
var DecodedSignedRequest = FacebookWebContext.Current.SignedRequest.Data;
SignedRequestData = DecodedSignedRequest
var RawRequestData = (IDictionary<string, object>)SignedRequestData;
foreach (KeyValuePair<string, object> paird in RawRequestData)
{
Response.Write("key =" + paird.Key.ToString() + " value =" + paird.Value.ToString() + "<br/>");
}
if (RawRequestData.ContainsKey("page"))
{
Facebook.JsonObject RawPageData = (Facebook.JsonObject)RawRequestData["page"];
if (RawPageData.ContainsKey("liked"))
{
if (bool.Parse(RawPageData["liked"].ToString()))
{
LikedContent.Visible = true;
if (!IsPostBack)
{
PageSetup();
}
}
else
{
UnlikedContent.Visible = true;
}
}
else
{
UnlikedContent.Visible = true;
}
}
else
{
DefaultContent.Visible = true;
}
}
else
{
DefaultContent.Visible = true;
}
}
此问题是,如果我在应用程序上有多个页面,则会遇到跨域问题.可以很容易地解决此问题,例如使用gloabl.asac.cs文件中的p3p标头. 问题仍然存在于野生动物园中.
The problem with this is that if i have multiple pages on the app i get cross domain issues. can fix this quite easily for ie using the p3p header in the gloabl.asac.cs file. the issue however still remains in safari.
现在,C#sdk的当前版本6建议使用facebook javascript sdk来调用打开的图形并检查用户是否喜欢页面,然后将其传递给我想知道什么是最好的背后的代码制作Facebook粉丝页面标签应用的实践?
Now that the current version 6 of the c# sdk recommends using the facebook javascript sdk to call the open graph and check that the user likes a page and then pass it to the code behind i was wanting to know what actually is the best practice for building facebook fan page tab apps?
每当我使用javascript sdk访问用户信息时,我都会弹出一个框来授权该应用程序.我不要这个有办法解决这个问题吗?
When ever i access the users information using the javascript sdk i get a pop up box to authorise the app. i don't want this. is there a way round this?
欢呼
推荐答案
您可以在后面的代码中调用这样的图形api方法
You can call graph api method like this in code behind
void CallFacebookApi(string oAuthToken, string userId)
{
string userLikeUrl = "https://graph.facebook.com/me/Likes/" + pageId +"?access_token=" + oAuthToken;
response = requestFBData(userLikeUrl);
if (response.Length > 0)
{
JObject userLike = JObject.Parse(response);
int count = userLike["data"].Count();
if (count > 0){
//user liked your page.
}
else {
//user do not liked your page yet
}
}
}
public string requestFBData(string action)
{
string results = string.Empty;
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(action);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
results = sr.ReadToEnd();
sr.Close();
}
catch (Exception e)
{
if (e.Message.Contains("400"))
{
//invalid reponse
}
}
return results;
}
这篇关于Facebook粉丝页面应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!