Webhooks with PHP/PostgreSQL
Options
Hey all,
I'm attempting to set up the Webhooks in PHP using my own webhost. I've gotten pretty far, I'm able to generate the database, and detect the hooks coming from the Photon server. I'm just having an issue with the JSON responses that I'm supposed to be returning.
When GetGameList is called, I receive the following:
Command
GetGameList
PHP Input Stream
{"AppId":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","AppVersion":"1.0","Region":"EU","UserId":"asdf"}
JSON encoded body
object(stdClass)#1 (4) {
["AppId"]=>
string(36) "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
["AppVersion"]=>
string(3) "1.0"
["Region"]=>
string(2) "EU"
["UserId"]=>
string(4) "asdf"
}
JSON Variables
AppId = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
AppVersion = 1.0
Region = EU
UserId = asdf
Processing Command
ReturnVal = {"Message":"","ResultCode":0,"Data":"[]"}
(I've also returned the array itself without the quotes. {"Message":"","ResultCode":0,"Data":[]} with the exact same result)
There are no games present in the database. So it's going to return an empty array. But this is what I get back in the Unity side of things:
Handling of successfull response failed with exception System.ArgumentException: Invalid JSON primitive: Array.
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
at System.Web.Script.Serialization.Java...
Could I get an example of the JSON string you are expecting for an empty array, and an example of what you are expecting when an array actually has something in it?
Thanks
Shane
I'm attempting to set up the Webhooks in PHP using my own webhost. I've gotten pretty far, I'm able to generate the database, and detect the hooks coming from the Photon server. I'm just having an issue with the JSON responses that I'm supposed to be returning.
When GetGameList is called, I receive the following:
Command
GetGameList
PHP Input Stream
{"AppId":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","AppVersion":"1.0","Region":"EU","UserId":"asdf"}
JSON encoded body
object(stdClass)#1 (4) {
["AppId"]=>
string(36) "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
["AppVersion"]=>
string(3) "1.0"
["Region"]=>
string(2) "EU"
["UserId"]=>
string(4) "asdf"
}
JSON Variables
AppId = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
AppVersion = 1.0
Region = EU
UserId = asdf
Processing Command
ReturnVal = {"Message":"","ResultCode":0,"Data":"[]"}
(I've also returned the array itself without the quotes. {"Message":"","ResultCode":0,"Data":[]} with the exact same result)
There are no games present in the database. So it's going to return an empty array. But this is what I get back in the Unity side of things:
Handling of successfull response failed with exception System.ArgumentException: Invalid JSON primitive: Array.
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
at System.Web.Script.Serialization.Java...
Could I get an example of the JSON string you are expecting for an empty array, and an example of what you are expecting when an array actually has something in it?
Thanks
Shane
0
Comments
-
The response for an empty database should look like this:
{"Data":{},"ResultCode":0}
The response for a list with two entries looks like this{ "Data": { "MyRoom1": { "ActorNr": 1, "Properties": { "lobby4Key": "lobby4Val", "lobby3Key": "lobby3Val" } }, "test": { "ActorNr": 1, "Properties": { "lobby4Key": "lobby4Val", "lobby3Key": "lobby3Val" } } }, "ResultCode": 0 }
0 -
Hi, Shane. Glad to see your progress on the way.
>>Could I get an example of the JSON string you are expecting for an empty array, and an example of what you are expecting when an array actually has something in it?
As i may see there is no need in doulbe quotes, so your array should looks like
"Data":[] instead of
"Data":"[]"
because in this case Data will have string value []
you may use http://www.jsoneditoronline.org/ in order to check your JSON data0 -
Thanks Philip and Chvetsov,
I've returned the following:
{"Message":"","ResultCode":0,"Data":[]} // This one makes the most sense to me.. but was getting the Invalid JSON primitive: Array error.
{"Message":"","ResultCode":0,"Data":"[]"} // I didn't think this would work, but it's technically good JSON so I gave it a shot
{"Message":"","ResultCode":0,"Data":""} // No dice
{"Message":"","ResultCode":0,"Data":{}} // I actually couldn't figure out how to make the php json_encode function do this. But I manually returned this on an empty array. Still got Invalid primitive.
{"Message":"","ResultCode":0,"Data":} (which is bad JSON I know.. but I was tilting at windmills at this point)
I'll continue to work at it.. I'm sure I'm just missing something painfully obvious. If anyone here is familiar with PHP and would like to take a look at the code, PM me and I'll be happy to share.0 -
Sending the following:
{"Message":"","ResultCode":0,"Data":[]}
Results in the following:WebRpc-Response: OperationResponse 219: ReturnCode: -1 (Handling of successfull response failed with exception System.NullReferenceException: Object reference not set to an instance of an object. at Photon.Hive.Rpc.RpcHandler.HandleSuccessHttpResponse(PeerBase peer, Byte operationCode, RpcRequest rpcRequest, AsyncHttpRequest request) in d:\dev\photon-socketserver-sdk_cloud\src-server\Hive\PhotonHive\Rpc\RpcHandler.cs:line 223). Parameters: {} UnityEngine.Debug:Log(Object) DemoGame:OnOperationResponse(OperationResponse) (at Assets/Demo/DemoGame.cs:47) ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[]) ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() ExitGames.Client.Photon.PhotonPeer:Service() ExitGames.Client.Photon.LoadBalancing.LoadBalancingClient:Service() (at Assets/LoadbalancingApi/LoadBalancingClient.cs:634) DemoGUI:Update() (at Assets/Demo/DemoGUI.cs:54)
I'm also having issues with inserting information into the database, but that's next on the agenda.. right now I'd just like to get to the bottom of this request.0