Unity www 产量返回请求在编辑器中有效,但在 fb 应用程序中不起作用
本文关键字:有效 但在 fb 不起作用 应用程序 编辑器 www 返回 请求 Unity | 更新日期: 2023-09-27 17:56:21
目前我的简化问题是这样的:
下面的代码在 Unity 编辑器中工作,我之前多次检查过 php,现在发送的 url 可以工作,并且它返回正确的值,但是将构建上传到要在 facebook 应用程序中使用的空间会破坏它由于某种原因,img 提供以显示它停止的位置。
其他一些细节:
环顾四周,所有迹象都表明它是 v3.0 的错误(我正在使用的版本是 v4.3.3f1),但是虽然我下面的代码在编辑器中工作没有问题,但当我将其构建上传到我提供的 html 空间时,它不会继续超过收益返回 www 请求。
在下面的块之前,登录的当前工作方式是初始化FB游戏对象,登录Facebook,检查没有错误,然后传回FB UserID,然后将其传递给下面的代码 - 它按预期工作。
快速编辑 - DB 连接器包含主 URL,下面的代码将 php get 的必要字符串添加到该 url 中。
我不知道从哪里开始尝试修复它,除了如图所示更改显示的文本,这有助于将其隔离到我在这里的问题。
粘住的登录屏幕的图像:https://i.stack.imgur.com/s9ocX.png
法典:
using UnityEngine;
using System.Collections;
using System;
public class ConnectToDataBase : MonoBehaviour {
public bool bDatabaseConnected = false;
public bool bConnectionFailed = false;
public string sFacebookID;
public WWWForm wwwForm;
public void vStartConnection()
{
var text = GameObject.FindGameObjectWithTag ("Other");
text.guiText.text = "Login : connectToDatabase: prepping query";
//call databasequeries and get sDBConnect
string sConnectPhp = GameObject.FindGameObjectWithTag("DBConnector").GetComponent<DatabaseQueries>().sDBConnect;
//now ready the url with the necessary code for php's get, and the FacebookID
string url = sConnectPhp + "?UserID=" + sFacebookID;
text.guiText.text = "Login : connectToDatabase: url being sent:'n" + url;
WWW wwwGet = new WWW(url);
text.guiText.text = "Login : connectToDatabase: wwwGet created";
text.guiText.text = "Login : connectToDatabase: starting coroutine";
StartCoroutine(Connect(wwwGet));
}
IEnumerator Connect(WWW www)
{
var text = GameObject.FindGameObjectWithTag("Other");
text.guiText.text = "Login : connectToDatabase: coroutine started - sending www request";
yield return www;
text.guiText.text = "Login : connectToDatabase: wwwGet yield return";
string sTemp = www.text;
if(www.error == null)
{
text.guiText.text = "Login : connectToDatabase: wwwGet has not errored";
string newString = sTemp.ToString();
int newInt = Convert.ToInt32(newString);
//print (newString);
text.guiText.text = "Login : connectToDatabase: checking wwwGet return as int";
if(newInt == 0)
{
//if successfully connected set to true
print ("connectToDatabase: olduser successful");
text.guiText.text = "Login : connectToDatabase: olduser successful";
bDatabaseConnected = true;
yield break;
}
else if(newInt == 1)
{
//if successfully connected set to true
print ("connectToDatabase: newuser successful");
text.guiText.text = "Login : connectToDatabase: newuser successful";
bDatabaseConnected = true;
yield break;
}
else if(newInt == 2)
{
//game connection has failed
print ("connectToDatabase: failed");
text.guiText.text = "Login : connectToDatabase: failed";
bDatabaseConnected = false;
bConnectionFailed = true;
yield break;
}
else
{
text.guiText.text = "Login : connectToDatabase: php did not return a 0/1/2 value";
}
}
else
{
//game connection has failed
print ("connectToDatabase: failed");
text.guiText.text = "Login : connectToDatabase: wwwGet has errored:'n" + www.error;
bDatabaseConnected = false;
bConnectionFailed = true;
yield break;
}
text.guiText.text = "Login : connectToDatabase: wwwGet if statement skipped entirely";
}
}
在浏览器中运行时有不同的规则。如此处所述,该应用程序处于沙盒模式,因此您需要添加跨域策略(我知道该链接适用于Flash Player,但同样的原则适用)。
最后,您需要将这样的东西保存在Web服务器根目录中的跨域.xml文件中。
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" secure="false"/>
</cross-domain-policy>