AJAX Call Does Not Trigger Action Method When Decorated With CanvasAuthorize

此生再无相见时 提交于 2020-01-06 05:27:26

问题


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


回答1:


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

You can implement this by yourself or use:

<%: Html.FacebookSignedRequest() %>


来源:https://stackoverflow.com/questions/6057973/ajax-call-does-not-trigger-action-method-when-decorated-with-canvasauthorize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!