Facebook C# SDK, AJAX in iFrame app

喜欢而已 提交于 2019-12-04 05:30:40

问题


I am making an iFrame application for Facebook using the Facebook C# SDK. I have it that the user is authenticating and I can get their username using the Graph API (FaceBookApp.Api("/userid"))

My problem now is that when I do an AJAX call to a page I can no longer use the Api. The userid is 0. When opening up FireBug the response from the request is "Unsupported get request." I suspect this has something to do with the face that the AJAX request is using a different session for the call and that session is not authenticated. I was wondering if there is any way to get around this? I known I could make the page I am requesting re-authenticate but that would mean I would have to reauth for every request which does not seem efficient. I am using Jquery to make the request.

Any help is much appreciated.

Thanks


回答1:


The issue is that with an ajax call in an iframe you must send the session info for the client to the server. Otherwise the FacebookApp has no way of knowing who the current user is. You can solve this in one of two ways.

  1. You can send the entire signed_request value to the server.
  2. You can use the Javascript SDK to get the users access token and send just that value to the server.

I think the first way is the best. All you need to do is change your ajax url to include the signed request like this:

var ajaxUrl = '/services/example?signed_request=<%=Request.Querystring["signed_request"] %>';

Then just make your call like normal with the new url. After that the FacebookApp class will read the session from the ajax request and you will be good to go.



来源:https://stackoverflow.com/questions/4182064/facebook-c-sharp-sdk-ajax-in-iframe-app

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