【问题标题】:How to check whether a facebook user liked my facebook page or not using ASP.Net如何使用 ASP.Net 检查 facebook 用户是否喜欢我的 facebook 页面
【发布时间】:2015-05-21 07:21:19
【问题描述】:
  1. 我想检查一个 facebook 用户是否喜欢我的 facebook 页面。我有很多使用 javascript 的解决方案,但我想在 ASP.Net 中实现这个要求。

  2. 我从以下链接复制了代码: http://duanedawnrae.com/Blog/post/2012/02/29/Determine-if-a-Facebook-user-Likes-your-page-with-ASPNET.aspx

  3. 我得到了下面的 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;
    }
}
  1. 以上代码包含一个包含单个函数的 web 服务。该函数包含四个输入参数并返回一个输出字符串。

  2. 但是当我运行这个网络服务时,我得到了错误,“值不能为空。参数名称:流”。出现此错误是因为“objStream”变量设置为空。请解决此问题,以便我可以得到正确的输出,因为我不知道如何实现我的要求。

【问题讨论】:

    标签: c# asp.net facebook facebook-graph-api


    【解决方案1】:

    Facebook 上不允许点赞,也不允许激励用户点赞您的主页。用户必须喜欢某些东西,因为他们真的想要,你不能以任何方式奖励他们。

    话虽如此,您需要user_likes 权限才能使用/me/likes,并且您需要获得 Facebook 的批准。这不会仅用于检查用户是否喜欢您的页面。

    顺便说一句,那篇文章是 2012 年的。从那以后发生了很多变化。

    【讨论】:

    • 如果用户已经登录并且他喜欢我们的页面,那么我们要检查用户是否喜欢我们的页面。
    • 我知道,但您要检查什么?你需要一个充分的理由来请求 user_likes。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    • 2013-08-14
    • 2011-11-15
    相关资源
    最近更新 更多