Facebook的C#SDK,AJAX在iframe应用程序 [英] Facebook C# SDK, AJAX in iFrame app

查看:126
本文介绍了Facebook的C#SDK,AJAX在iframe应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Facebook C#SDK一个iFrame应用为Facebook。我有它的用户进行身份验证,我可以使用图形API获得自己的用户名(FaceBookApp.Api(/用户id))

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"))

我现在的问题是,当我做一个AJAX调用一个网页,我可以不再使用的API。该用户ID为0。当开放萤火从请求的响应是不支持GET请求。我怀疑这事做与AJAX请求是使用不同的会议呼叫和会话没有验证过脸。我想知道是否有什么办法来解决这个问题?如果我知道我可以做我要求重新进行身份验证的页面,但是这将意味着我将不得不reauth每一个,这似乎并没有有效的请求。我使用jQuery来发出请求。

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.

任何帮助是非常AP preciated。

Any help is much appreciated.

感谢

推荐答案

问题是,在一个IFRAME一个Ajax调用必须发送客户端与服务器的会话信息。否则,FacebookApp没有办法知道谁是当前用户的。可以以两种方式之一解决这个问题。

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. 您可以发送整个signed_request值到服务器。
  2. 您可以使用JavaScript SDK,以获得用户的访问令牌,只是该值发送到服务器。

我认为第一种方式是最好的。所有你需要做的是改变你的AJAX的网址,包括像这样的签名的请求:

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]%>';

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

然后,只需让你的电话一样正常,新的URL。在那之后,FacebookApp类将从Ajax请求读取会话,你会好到哪里去。

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.

这篇关于Facebook的C#SDK,AJAX在iframe应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆