asp.net - Facebook Credits 与 C# SDK

标签 asp.net facebook facebook-c#-sdk

更新 从那以后我就能够让弹出窗口正常工作了。我删除/注释掉了下面使用的不必要的代码。由于某些奇怪的原因,我不得不从 ashx 切换到 aspx。只需确保您在数据库中查找的所有变量都存在:)

我在将 Facebook 积分应用到我的 Facebook 应用程序中时遇到一些问题。我正在使用Facebook C# SDK我确信我的 JavaScript 是干净的。我发现this博客很有帮助,但我在 javascript 回调中从 facebook 收到 AppInvalidDecodedResponse 错误。我最初只是想显示“购买”弹出窗口。这是我在应用程序设置中指定的 ashx 回调:

public void Page_Load(object sender, EventArgs e)
{

    string order_id = Request.Form["order_id"];
    string method = Request.Form["method"];        
    string order_info = Request.Form["order_info"];


    FacebookBuyItem theItem = new FacebookBuyItem();
    theItem.title = "item not found";
    theItem.price = "1";
    theItem.image_url = Utilities.GlobalSettings["WebDomain"];
    theItem.product_url = Utilities.GlobalSettings["WebDomain"];
    theItem.description = "item not found";

    if (method == "payments_get_items")
    {

        //order_info = (string)data["order_info"];
        //order_info = order_info.Substring(1, (order_info.Length - 2));
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.Connection = new SqlConnection(Utilities.PluginSettings["SQL Database"]["ConnectionString"]);
            cmd.Connection.Open();

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.CommandText = "dbo.GetItem";

            cmd.Parameters.Add("@ItemID", System.Data.SqlDbType.Int).Value = int.Parse(order_info);

            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                theItem.title = dr["ItemName"].ToString();
                theItem.price = dr["FacebookCreditCost"].ToString();
                theItem.image_url = dr["ThumbPath"].ToString();
                theItem.product_url = dr["ThumbPath"].ToString();
                theItem.description = dr["Description"].ToString();
            }
            dr.Close();

            cmd.Connection.Close();
        }
    }
    //Utilities.Dump(order_info, order_id, method);
    var res = new Dictionary<string, object>();
    res["method"] = method;
    //res["order_id"] = order_id;
    res["content"] = new object[] { theItem };


    JavaScriptSerializer jss = new JavaScriptSerializer();
    string ob = jss.Serialize(res);
    //ob = ob.Replace("#$", @"\/");
    Response.ContentType = "application/json";
    Response.Write(ob);
    Response.End(); 
}

最佳答案

我是 Facebook 的一名工程师,希望能为您提供帮助。解码响应无效意味着回调在 payment_get_items 调用期间未向 Facebook 提供必要且格式正确的商品信息。好消息是,Facebook 正在从您的回调中获取某些信息,但不是正确的某些信息。我对 C# 没有经验,但首先,我会尝试像下面那样对您的商品名称、价格等进行硬编码,并检查它是否按预期工作。

        theItem.title = 'BFF Locket';
        theItem.price = 1;
        theItem.image_url = 'http://www.facebook.com/images/gifts/21.png';
        theItem.product_url = 'http://www.facebook.com/images/gifts/21.png';
        theItem.description = 'This is a BFF Locket...';

如果您仍然遇到问题,请告诉我,我可以进一步调查此问题。

关于asp.net - Facebook Credits 与 C# SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6962995/

相关文章:

c# - AjaxToolkit 日历扩展器上未捕获的 Sys.ArgumentOutOfRangeException : Sys. ArgumentOutOfRangeException : Value must be an integer.

java - restFB post as page step by step 工作示例

c# - Facebook C# ASP.NET SDK 模拟Pandora 体验?

c# - ASP.Net MVC 回发格式化的时间跨度

asp.net - 在 LINQ-to-Entities 中连接字符串

javascript - 无法在 Firefox OS 上的 Facebook 和 Twitter native 应用程序上访问 'share' URL

javascript - 使用 JS API 检查用户是否喜欢页面?

c# - client.get ("me/statuses") 使用 C# Facebook SDK 5.0.3 返回空的 "data"数组

c# - 链接描述被截断

c# - 为什么更改时区后 UTC 偏移量相同?