- Home /
Uniweb(sockets) + Facebook
Hi, I'm trying to connect to Facebook Graph API using UniWeb plugin. Everything works fine on iOS, but on the web player I'm getting this exception:
System.Security.SecurityException: Unable to connect, as no valid crossdomain policy was found
at System.Net.Sockets.Socket.Connect_internal (IntPtr sock, System.Net.SocketAddress sa, System.Int32& error, Boolean requireSocketPolicyFile) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x00000] in <filename unknown>:0
The same example works ok if I connect using WWW instead of UniWeb.
This is the relevant code:
// This works ok
IEnumerator GetUserInfoWWW()
{
WWW www = new WWW("https://graph.facebook.com/100002347686605?fields=id,name,friends&access_token=" + accessToken);
yield return www;
response = www.text;
error = www.error;
}
// This doesn't work. I get System.Security.SecurityException: Unable to connect, as no valid crossdomain...
IEnumerator GetUserInfoUniWeb()
{
var request = new HTTP.Request("GET", "https://graph.facebook.com/100002347686605?fields=id,name,friends&access_token=" + accessToken);
request.Send();
while(!request.isDone) yield return new WaitForEndOfFrame();
if(request.exception != null)
{
Debug.LogError(request.exception);
}
else
{
var response = request.response;
Debug.Log(response.status);
Debug.Log(response.GetHeader("Content-Type"));
Debug.Log(response.Text);
}
}
I am missing something? UniWeb uses sockets to implement the http client, I don't know if this is relevant to this situation.
The UniWeb documentation says something about calling PrefetchSocketPolicy in order to the examples to work on the web player. I'm calling it like this:
Security.PrefetchSocketPolicy("https://graph.facebook.com", 843);
But it doesn't makes any difference.
I will appreciate any help. Thanks!
Does Facebook support a socket policy file on port 843 on graph.facebook.com?
Hmm, I just ran a test and it seems it doesn't:
This is what I get against graph.facebook.com:
i$$anonymous$$ac:~ murdock$ telnet graph.facebook.com 843
Trying 31.13.85.16...
Connected to star.c10r.facebook.com.
Escape character is '^]'.
<policy-file-request/>
Connection closed by foreign host.
And this is when I connect to my own server (which is running the socket policy server provided with Unity):
i$$anonymous$$ac:~ murdock$ telnet 172.16.48.128 843
Trying 172.16.48.128...
Connected to cgwks419.comp.local.
Escape character is '^]'.
<policy-file-request/>
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" to-ports="1200-1220"/>
</cross-domain-policy>"Connection closed by foreign host.
This means that I can't connect to graph API using UniWeb plugin? I'm lost, I have very little experience with servers.
Not sure. If Uniweb uses sockets, then in a webplayer it'll trigger the fetch of the socket policy file. If Facebook doesn't have one, then the security policy will stop you using sockets.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103215im_/https://answers.unity.com/themes/thub/images/avi.jpg)