用CanvasAuthorize装饰时AJAX调用不触发Action方法

发布于 2024-11-08 13:39:12 字数 1126 浏览 0 评论 0原文

我正在尝试通过我的 FB 应用程序将其发布在墙上,从而在 Facebook 上共享项目。我也在客户端和服务器端 (ASP.NET MVC3) 上设置了所有内容,但我注意到,当 ActionMethod 用 CanvasAuthorize 属性装饰时,该方法根本不会被触发。那我有什么可以做的吗?

PS:我通过 AJAX 调用检查了发布的数据,在那一端一切似乎都很好。此外,如果我注释 [CanvasAuthorize] 行,该方法就会被触发并且参数都很好,除了当我到达 fb.Post() 调用时,它抱怨没有有意义的 access_token 。

    //[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);
    }

有什么想法吗?

更新:

以下是后续内容:将signed_request与AJAX调用一起传递给用CanvasAuthorize装饰的ActionMethod

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: 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);
    }

Any ideas?

UPDATE:

Here's a follow-up: Passing the signed_request along with the AJAX call to an ActionMethod decorated with CanvasAuthorize

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空袭的梦i 2024-11-15 13:39:12

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

您可以自己实现或使用:

<%: Html.FacebookSignedRequest() %>

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

You can implement this by yourself or use:

<%: Html.FacebookSignedRequest() %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文