3
更新 我已經能夠得到彈出工作。我刪除/註釋掉了我在下面使用的不必要的代碼。出於某種奇怪的原因,我必須從我的ashx切換到aspx。只要確保你在數據庫中查找到的所有變量都存在:)Facebook的積分與C#SDK
我在facebook應用中執行facebook credits有一些問題。我使用的是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();
}
感謝您的幫助,但我仍然有問題。首先,很難判斷它是否真的被調用。在我的回調ashx中,我記錄了一個入口數據庫,而不管控制流(頂層,我們做的第一件事)。手動調用時,我看到記錄被轉儲到數據庫中,但是當通過我們的應用程序調用時,我們得到了無效解碼的響應,但沒有任何數據被放入數據庫,就好像它從未被調用一樣。有什麼想法嗎?提前致謝。 –
我回顧了應用回調下的FB積分api,並試圖在例子之後鏡像我的返回:'code' {「content」:[{「title」:「[Test Mode] Unicorn」,「description」:「[Test Mode ]擁有你自己的神獸!「,」price「:2,」image_url「:」http:\/\/www.facebook.com \/images \/gifts \ /21.png「,」product_url「:」http :\/\/www.facebook.com \/images \/gifts \ /21.png「}],」method「:」payments_get_items「} 我改變了'res'對象以省略'order_id'部分,而我刪除ob.replace混亂。從那裏我能夠得到樣本彈出窗口,然後開始調試數據庫查找代碼中的錯誤。謝謝 –
好聽,讓我知道我可以進一步協助。 – DSchultz