2011-08-05 47 views
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(); 
} 

回答

1

我是Facebook的工程師,希望能在這裏幫忙。無效的解碼響應意味着在payments_get_items調用期間回調沒有提供必要且格式正確的商品信息。好消息是,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...'; 

讓我知道如果你仍然有問題,我可以進一步研究。

+0

感謝您的幫助,但我仍然有問題。首先,很難判斷它是否真的被調用。在我的回調ashx中,我記錄了一個入口數據庫,而不管控制流(頂層,我們做的第一件事)。手動調用時,我看到記錄被轉儲到數據庫中,但是當通過我們的應用程序調用時,我們得到了無效解碼的響應,但沒有任何數據被放入數據庫,就好像它從未被調用一樣。有什麼想法嗎?提前致謝。 –

+1

我回顧了應用回調下的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混亂。從那裏我能夠得到樣本彈出窗口,然後開始調試數據庫查找代碼中的錯誤。謝謝 –

+1

好聽,讓我知道我可以進一步協助。 – DSchultz