开发者

FacebookSDK Cross Domain Receiver Problem

开发者 https://www.devze.com 2023-02-02 13:34 出处:网络
Hi can somebody help me.I can\'t get rid of this error message in Chrome 9.0 beta, Chrome 8.0 or Firefox 3.6.13:

Hi can somebody help me. I can't get rid of this error message in Chrome 9.0 beta, Chrome 8.0 or Firefox 3.6.13:

"Unsafe JavaScript attempt to access frame with URL 'http://apps.facebook.com/myapp/' from frame with URL 'http://myapp.dyndns-office.com/'. Domains, protocols and ports must match."

I'm using the FacebookSDK version 4.1.1 CSMvcFacebookApp in the Samples folder.

I have this script in my Site.Master page located in Views/Shared:


<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        FB_RequireFeatures(['CanvasUtil'], function () {
            FB.XdComm.Server.init("<%= ResolveUrl("~/xd_receiver.htm") %>");
            FB.CanvasClient.startTimerToSizeToContent();
        });
    });
</script>

I have xd_receiver.htm in my root directory, and presumed that the above javascript code was all I needed to do verify my domain with facebook. Is my presumption correct or has things changed? I even tried moving the FB code out of the JQuery ready function like so:


<script language="javascript" type="text/javascript">
    FB_RequireFeatures(['CanvasUtil'], function () {
        FB.XdComm.Server.init("<%= ResolveUrl("~/xd_receiver.htm") %>");
        FB.CanvasClient.startTimerToSizeToContent();
    });
</script>

But this doesn't work either ... Can anybody shed some light as to what I'm doing wrong or how I get xd file to work using the SDK/MVC IFrame solution...

FB.CanvasClient.startTimerToSizeToContent() is firing because I don't have the scroll bars appear in my application, so that proves that 开发者_Python百科FB_RequireFeatures function is working. But as to whether FB.XdComm.Server.init is doing it's part I'm just not sure as to how I go about testing this ???

The content of my xd_receiver.html file in my root directory is:


<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>cross domain receiver page</title>
</head>
<body>
        <!--
                As described in: http://wiki.developers.facebook.com/index.php/Cross-domain_communication_channel
        -->
    <script src="http://static.ak.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script>

</body>
</html>-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script>
</body>
</html>

XdCommReceiver.js exists as I just copied the pasted the url into the browser. Are my paths correct or have facebook up and change the url's etc ... ?

I understand that my main concern here is that Safari won't run my app at all if I don't get this cross domain stuff sorted out now.

Any help here would be much appreciated :-\

Thanks Rob

<< ADDITIONAL COMMENT >>

Is there a built in mechanism in the latest version of the FacebookSDK v 4.1.1 to make this cross domain stuff just work? Did the developers of the SDK think about this issue? Or have I just brought up a future feature ... :-\


Here's the code you need to have in your cross-domain scripting channel file:

<html><body><script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script></body></html>

Here's the code to initialize the FB Javascript SDK. Put this at the very end of your HTML files, substituting in the appropriate values and URLs.

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script><script type="text/javascript">FB.init({appId: '1234567890', status: true, cookie: true, xfbml: true,channelUrl: 'http://example.com/xss_channel.htm'});</script>

Optionally, put this in your web.config where the XSS channel file is located. This lets browsers cache the file indefinitely as recommended by Facebook.

  <?xml version="1.0" encoding="UTF-8"?>
  <configuration>
      <location path="xss_channel.htm">
          <system.webServer>
              <httpProtocol>
                  <customHeaders>
                      <add name="Expires" value="Tue, 01 Jan 2030 16:00:00 GMT" />
                  </customHeaders>
              </httpProtocol>
          </system.webServer>
      </location>
  </configuration>

And finally, if you're using XFBML, place this namespace definition in your <html> to make XFBML work in IE: xmlns:fb="http://www.facebook.com/2008/fbml"


You are using the old Facebook Connect Javascript. The Facebook C# SDK is not compatible with the old Javascript SDK. You should use the new Facebook Javascript SDK (as was included in the sample). http://developers.facebook.com/docs/reference/javascript/

0

精彩评论

暂无评论...
验证码 换一张
取 消