[英]How to check whether a facebook user liked my facebook page or not using ASP.Net
我想检查一个Facebook用户是否喜欢我的Facebook页面。 我有很多使用javascript的解决方案,但我想在ASP.Net中实现此要求。
我从以下链接复制了代码: http : //duanedawnrae.com/Blog/post/2012/02/29/Determine-if-a-Facebook-user-Likes-your-page-with-ASPNET.aspx
我得到了下面的同样适用的ASP.Net代码。
ASP.Net代码:
public class WebService : System.Web.Services.WebService
{
[WebMethod()]
public string GetFacebookLikeStatus(string fbpageid, string fbappid, string fbtoken, string fburl)
{
string strReturn = null;
// Placeholder for the Facbook "like" API call
string strURL = null;
strURL = "https://graph.facebook.com/me/likes?access_token=" + fbtoken;
// Placeholder for the Facebook GET response
WebRequest objGETURL = null;
objGETURL = WebRequest.Create(strURL);
// Declare response stream
Stream objStream = null;
// Declare The Facebook response
string strLine = null;
// Declare a count on the search term
int intStr = 0;
try
{
// Create an instance of the StreamReader
StreamReader objReader = new StreamReader(objStream);
// Get the response from the Facebook API as a JSON string.
// If access_token is not correct for the logged
// on user Facebook returns (400) bad request error
objStream = objGETURL.GetResponse().GetResponseStream();
// If all is well
try
{
// Execute the StreamReader
strLine = objReader.ReadToEnd().ToString();
// Check if Facebook page Id exists or not
intStr = strLine.IndexOf(fbpageid); // if valid return a value
if (intStr > 0)
{
strReturn = "1";
// if not valid return a value
}
else
{
strReturn = "0";
}
objStream.Dispose();
}
catch (Exception ex)
{
// For testing comment out for production
strReturn = ex.ToString();
// Uncomment below for production
//strReturn = "Some friendly error message"
}
}
catch (Exception ex)
{
// For testing comment out for production
strReturn = ex.ToString();
// Uncomment below for production
//strReturn = "Some friendly error message"
}
return strReturn;
}
}
上面的代码包含一个Web服务,其中包含一个功能。 该函数包含四个输入参数,并返回单个输出字符串。
但是,当我运行此Web服务时,出现错误,“值不能为null。 参数名称:stream”。 由于“ objStream”变量设置为null,因此将出现此错误。 请解决此问题,以使我可以得到正确的输出,因为我不知道如何实现我的要求。
在Facebook上不允许“赞门”,也不能激励用户喜欢您的信息页。 用户之所以只喜欢他们真正想要的东西,是您无法以任何方式奖励他们。
话虽如此,您将需要user_likes
权限才能使用/me/likes
,并且需要得到Facebook的批准。 仅检查用户是否喜欢您的页面不会发生这种情况。
顺便说一句,那是2012年的文章。此后发生了很多变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.