用CanvasAuthorize装饰时AJAX调用不触发Action方法
我正在尝试通过我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用通过 ajax 调用传递的隐藏字段。
您可以自己实现或使用:
Use a hidden field which you pass with your ajax call.
You can implement this by yourself or use: