本文介绍了使用CanvasAuthorize进行装饰时,AJAX调用不会触发操作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过FB应用程序将其发布在墙上,以在Facebook上分享项目。我在客户端和服务器端设置了一切(ASP.NET MVC3),但是我注意到,当ActionMethod使用 CanvasAuthorize 属性进行装饰时,该方法根本没有触发。所以有什么可以做的吗?

I am trying to share items on Facebook by posting them on the wall via my FB app. I setup everything on the client side and the server side as well (ASP.NET MVC3), but I noticed that when the ActionMethod is decorated with the CanvasAuthorize attribute, the method does not get triggered at all. So is there anything I could do?

P.S:我通过AJAX调用查看了发布的数据,一切似乎都很好。此外,如果我评论 [CanvasAuthorize] 行,方法将被触发,并且params都可以正常,除非我到达 fb.Post ()调用,它抱怨没有access_token是有道理的。

P.S: I checked the posted data by the AJAX call and everything seemed fine on that end. Moreover, if I comment the [CanvasAuthorize] line, the method gets triggered and the params are all fine, except when I get to the fb.Post() call, it complains that there is no access_token which makes sense.

    //[CanvasAuthorize(Permissions = "publish_stream")]
    public ActionResult PostItem(string message, string link, string picture, string name)
    {
        var fb = new FacebookWebClient();
        var postArgs = new Dictionary<string, string>();
        postArgs["message"] = message;
        postArgs["link"] = link;
        postArgs["picture"] = picture;
        postArgs["name"] = name;
        fb.Post("/me/feed", postArgs);
        return Json(new {result = "success"}, JsonRequestBehavior.AllowGet);
    }

任何想法?

更新:

这是一个后续行动:

推荐答案

使用您通过ajax调用传递的隐藏字段。

Use a hidden field which you pass with your ajax call.

您可以实现此自己或使用:

You can implement this by yourself or use:

<%: Html.FacebookSignedRequest() %>

这篇关于使用CanvasAuthorize进行装饰时,AJAX调用不会触发操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:05