Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 移动web应用程序中的Facebook信用回调_Asp.net_Asp.net Mvc 3_Facebook Credits - Fatal编程技术网

Asp.net 移动web应用程序中的Facebook信用回调

Asp.net 移动web应用程序中的Facebook信用回调,asp.net,asp.net-mvc-3,facebook-credits,Asp.net,Asp.net Mvc 3,Facebook Credits,我正在尝试使用asp.net和MVC3创建一个Facebook移动应用程序,并将Facebook积分集成为一种支付方式。首先,考虑到最近的公告,现在是否有可能拥有一个接受Facebook信用的移动web应用程序 如果是这样的话,我就以下面的文章中提供的例子为例 并执行以下控制器操作: public JsonResult CallBack() { string fborder_info = Request.Form["order_info"]; string fborder_id

我正在尝试使用asp.net和MVC3创建一个Facebook移动应用程序,并将Facebook积分集成为一种支付方式。首先,考虑到最近的公告,现在是否有可能拥有一个接受Facebook信用的移动web应用程序

如果是这样的话,我就以下面的文章中提供的例子为例

并执行以下控制器操作:

public JsonResult CallBack()
{
    string fborder_info = Request.Form["order_info"];
    string fborder_id = Request.Form["order_id"];
    string fbmethod = Request.Form["method"];



    if (fbmethod == "payments_get_items")
    {

        fborder_info = fborder_info.Substring(1, (fborder_info.Length - 2)); // remove the quotes 

        ulong credscost = 2; // Price of purchase in facebook credits 

        var theItem = new FacebookBuyItem()
        {
            item_id = 123456789,
            description = "Own yours today!",
            price = credscost,
            title = "Digital Unicorn",
            product_url = "http://www.facebook.com/images/gifts/21.png",
            image_url = "http://www.facebook.com/images/gifts/21.png"
        };

        var res = new Dictionary<string, object>();
        res["method"] = fbmethod;
        res["order_id"] = fborder_id;
        res["content"] = new object[] { theItem };
        var jss = new JavaScriptSerializer();
        var ob = jss.Serialize(res);
        ob = ob.Replace("#$", @"\/".Replace("//", @"\/"));

        return Json(ob, JsonRequestBehavior.AllowGet);
    }

    return null;
}
publicjsonresult回调()
{
字符串fborder\u info=请求。表单[“order\u info”];
字符串fborder_id=Request.Form[“order_id”];
字符串fbmethod=Request.Form[“method”];
如果(fbmethod==“付款获取项目”)
{
fborder_info=fborder_info.Substring(1,(fborder_info.Length-2));//删除引号
ulong credscost=2;//facebook积分中的购买价格
var Iteem=新的FacebookBuyItem()
{
项目id=123456789,
description=“今天拥有你的!”,
价格=信用成本,
title=“数字独角兽”,
产品url=”http://www.facebook.com/images/gifts/21.png",
图像_url=”http://www.facebook.com/images/gifts/21.png"
};
var res=新字典();
res[“方法”]=FB方法;
res[“订单id”]=fborder\U id;
res[“content”]=新对象[]{item};
var jss=新的JavaScriptSerializer();
var ob=jss.Serialize(res);
ob=ob.Replace(“\$”,@“\/”。Replace(“/”,@“\/”);
返回Json(ob,JsonRequestBehavior.AllowGet);
}
返回null;
}
我已经验证了facebook正在请求回调,我还捕获了返回的响应,其中似乎包含显示购买对话框所需的所有信息,但我仍然收到以下错误消息:

API错误代码:1151 API错误描述:抱歉,此应用可能没有资格接受Facebook积分。如果此应用以前接受过积分,请重试。 错误消息:无效的应用程序

当从移动浏览器进行测试时:

抱歉,我们无法处理您的付款。您尚未为此交易收取费用。请再试一次

我还注意到我的回拨被请求了两次,这似乎也不对

如果您能深入了解如何启动并运行我的集成,我们将不胜感激。我的Facebook应用程序ID是177876855621874


谢谢。

更新:因此,为了测试在上给出的示例,我反复使用了给出的示例,并返回到webforms。为了使此解决方案在asp.net MVC3应用程序中工作,我必须将操作类型更改为HttpResponse,而不是JsonResult,这是有意义的,因为JsonResult忽略了通常包含在HttpResponse中的元素

所以控制器的动作最终是这样的:

[HttpPost]
public HttpResponse CallBack()
{
    if (Request.Form["signed_request"] != null)
    {
        var decodeFbSignedRequest = FacebookSignedRequest.Parse(FacebookApplication.Current.AppSecret,
                                                            Request.Form["signed_request"]);

        LogHelper.MicroLogMsg("SIGNED REQUEST DECODE:: " + decodeFbSignedRequest.Data);
    }

    string fborder_id = Request.Form["order_id"];
    string fbmethod = Request.Form["method"];
    string fborder_info = Request.Form["order_info"];  // Use this to look up a product on the database..

    if (fbmethod == "payments_get_items")
    {
        int credscost = 2; // Price of purchase in facebook credits 

        var theItem = new FacebookBuyItem()
        {
            item_id = "123456AA",
            description = "[Test Mode] Own yours today!",
            price = credscost,
            title = "[Test Mode] Digital Unicorn",
            product_url = @"http:\/\/www.facebook.com\/images\/gifts\/21.png",
            image_url = @"http:\/\/www.facebook.com\/images\/gifts\/21.png"
        };

        // Return the initial response to FB 
        //------------------------------------------ 
        var res = new Dictionary<string, object>();
        res["method"] = fbmethod;
        res["content"] = new object[] { theItem };

        var jss = new JavaScriptSerializer();
        string ob = jss.Serialize(res);

        LogHelper.MicroLogMsg(ob);

        Response.ContentType = "application/json";
        Response.Write(ob);
        Response.End();
    }

    return null;
}
[HttpPost]
公共HttpResponse回调()
{
if(请求表[“已签名的请求”!=null)
{
var decodeFbSignedRequest=FacebookSignedRequest.Parse(FacebookApplication.Current.AppSecret,
申请表格[“已签署的申请”];
LogHelper.MicroLogMsg(“签名请求解码::”+decodeFbSignedRequest.Data);
}
字符串fborder_id=Request.Form[“order_id”];
字符串fbmethod=Request.Form[“method”];
字符串fborder_info=Request.Form[“order_info”];//使用此选项在数据库中查找产品。。
如果(fbmethod==“付款获取项目”)
{
int credscost=2;//facebook信用卡中的购买价格
var Iteem=新的FacebookBuyItem()
{
item_id=“123456AA”,
description=“[Test Mode]今天拥有你的,
价格=信用成本,
title=“[测试模式]数字独角兽”,
产品url=@“http:\/\/www.facebook.com\/images\/gifts\/21.png”,
image\u url=@“http:\/\/www.facebook.com\/images\/gifts\/21.png”
};
//将初始响应返回给FB
//------------------------------------------ 
var res=新字典();
res[“方法”]=FB方法;
res[“content”]=新对象[]{item};
var jss=新的JavaScriptSerializer();
字符串ob=jss.Serialize(res);
LogHelper.MicroLogMsg(ob);
Response.ContentType=“application/json”;
响应。写入(ob);
Response.End();
}
返回null;
}
我希望这能帮助任何为Facebook Credits实现MVC3的人