I tried to do it manually using the chrome extension and now I am getting the error “app_id not found” though I am quite sure I copied it correctly.
Finally got it to work!!!
Just for your info. The following line will need to be included when using https with curl.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
You guys might want to update your PHP example in your documentation. I will try out Android next. :)
Excellent! Glad you got it working :). That’s interesting what the solution turned out to be, I’ll investigate why that line was needed and update our documentation shortly.
I can get push notifications working via the Chrome rest client but not via Python (I have identical code). I assume it has something to do with the SSL cert? do I need to use pyCurl and pycurl.SSL_VERIFYHOST = false?
Python code:
import requests import json jtemp = "{\"app\_id\":\"removed\",\"isIos\": true,\"isAndroid\":false,\"included\_segments\": [\"All\"],\"contents\": {\"en\":\"Hello World 3\"}}" auth = ("Authorization: Basic ", "removed") headers = {"Content-type": "application/json"} post\_url = "https://gamethrive.com/api/v1/notifications".format(auth[0]) r = requests.put(post\_url, auth=auth, headers=headers, data=jtemp) print jtemp
Thanks In Advance
Finally got code php code working to push a notification/.
\<?php $ch = curl\_init(); curl\_setopt($ch, CURLOPT\_URL, "https://gamethrive.com/api/v1/notifications"); curl\_setopt($ch, CURLOPT\_HTTPHEADER, array('Authorization: Basic your\_rest\_api\_key')); curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, TRUE); curl\_setopt($ch, CURLOPT\_HEADER, FALSE); curl\_setopt($ch, CURLOPT\_POST, TRUE); curl\_setopt($ch, CURLOPT\_POSTFIELDS, "{\"app\_id\":\"your\_app\_id\",\"isIos\": true,\"isAndroid\":false, \"include\_player\_ids\": [\"your\_player\_id\"],\"contents\": {\"en\":\"Hello World 3\"}}"); curl\_setopt($ch, CURLOPT\_HTTPHEADER, array("Content-Type: application/json")); curl\_setopt($ch, CURLOPT\_SSL\_VERIFYPEER, false); $response = curl\_exec($ch); curl\_close($ch); var\_dump($response); ?\>
Glad you got the PHP version working!
Not sure about the Python version. I’ve found this tool to be pretty useful for tracking down these kinds of problems: http://requestb.in/
You can temporarily change the GameThrive API urls to requestbin and see if there are any differences between your PHP and Python version.
Thanks for posting FearTec, useful head start.
Hi guys,
Where do you get the server-side API document from ? I checked their site ( http://docs.gamethrive.apiary.io/ ) but didn’t see any.
thanks
Hey Yosu. That is the server side documentation page.
We don’t have any server specific plugins, but you can interact with our API by making HTTP requests from whatever programming language you’re using on your server.
In our API docs, you can get an example of how to make the http requests from various programming languages by clicking on the documentation boxes. Make sure to make them to https://gamethrive.com/api/v1/… instead of https://gamethrive.apiary-mock.com/api/v1/ (which is what the examples have) .
Hi I’m using FearTec PHP code and just changed it to work with segments, as I want to notify all users and I get this error:
string(49) "{“errors”:[“Segments require a valid auth key.”]}"
I am using the REST API KEY that’s in my app settings page, so not sure why I am getting that error. Maybe I need to set up something else inside Gamethrive?
Any ideas?
This is the code:
\<?php $ch = curl\_init(); curl\_setopt($ch, CURLOPT\_URL, "https://gamethrive.com/api/v1/notifications"); curl\_setopt($ch, CURLOPT\_HTTPHEADER, array("Authorization: Basic my-rest-api-key-from-app-settings-page")); curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, TRUE); curl\_setopt($ch, CURLOPT\_HEADER, FALSE); curl\_setopt($ch, CURLOPT\_POST, TRUE); curl\_setopt($ch, CURLOPT\_POSTFIELDS, "{\"app\_id\":\"my-app-id-from-app-setting-page\",\"isIos\": false,\"isAndroid\":true,\"included\_segments\": [\"All\"],\"contents\": {\"en\":\"Hello World 3\"}}"); curl\_setopt($ch, CURLOPT\_HTTPHEADER, array("Content-Type: application/json")); curl\_setopt($ch, CURLOPT\_SSL\_VERIFYPEER, false); $response = curl\_exec($ch); curl\_close($ch); var\_dump($response); ?\>
That looks about right. Maybe try removing the part that sets CURLOPT_HEADER to false?
If that doesn’t work, could you try using RequestBin (http://requestb.in/) to check what’s getting sent and paste the ouput here?
Hi,
Following george18 advice used requestb.in and looked like the only header sent was the content-type, found out that only the last header will be caught hence changed the code to this and now it works:
\<?php $ch = curl\_init(); curl\_setopt($ch, CURLOPT\_URL, "https://gamethrive.com/api/v1/notifications"); $headers = array( 'Content-type: application/json', 'Authorization: Basic my-rest-api-key-from-app-settings-page', ); curl\_setopt($ch, CURLOPT\_HTTPHEADER, $headers); curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, TRUE); curl\_setopt($ch, CURLOPT\_HEADER, FALSE); curl\_setopt($ch, CURLOPT\_POST, TRUE); curl\_setopt($ch, CURLOPT\_POSTFIELDS, "{\"app\_id\":\"my-app-id-from-app-setting-page\",\"isIos\": false,\"isAndroid\":true,\"included\_segments\": [\"All\"],\"contents\": {\"en\":\"Hello World 3\"}}"); curl\_setopt($ch, CURLOPT\_SSL\_VERIFYPEER, false); $response = curl\_exec($ch); curl\_close($ch); var\_dump($response); ?\>
Changing CURLOPT_HEADER to false did not affect.
Thank for the advice !
Great! Glad it’s working now & thanks for sharing the solution.
I can get push notifications working via the Chrome rest client but not via Python (I have identical code). I assume it has something to do with the SSL cert? do I need to use pyCurl and pycurl.SSL_VERIFYHOST = false?
Python code:
import requests import json jtemp = "{\"app\_id\":\"removed\",\"isIos\": true,\"isAndroid\":false,\"included\_segments\": [\"All\"],\"contents\": {\"en\":\"Hello World 3\"}}" auth = ("Authorization: Basic ", "removed") headers = {"Content-type": "application/json"} post\_url = "https://gamethrive.com/api/v1/notifications".format(auth[0]) r = requests.put(post\_url, auth=auth, headers=headers, data=jtemp) print jtemp
Thanks In Advance
Finally got code php code working to push a notification/.
\<?php $ch = curl\_init(); curl\_setopt($ch, CURLOPT\_URL, "https://gamethrive.com/api/v1/notifications"); curl\_setopt($ch, CURLOPT\_HTTPHEADER, array('Authorization: Basic your\_rest\_api\_key')); curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, TRUE); curl\_setopt($ch, CURLOPT\_HEADER, FALSE); curl\_setopt($ch, CURLOPT\_POST, TRUE); curl\_setopt($ch, CURLOPT\_POSTFIELDS, "{\"app\_id\":\"your\_app\_id\",\"isIos\": true,\"isAndroid\":false, \"include\_player\_ids\": [\"your\_player\_id\"],\"contents\": {\"en\":\"Hello World 3\"}}"); curl\_setopt($ch, CURLOPT\_HTTPHEADER, array("Content-Type: application/json")); curl\_setopt($ch, CURLOPT\_SSL\_VERIFYPEER, false); $response = curl\_exec($ch); curl\_close($ch); var\_dump($response); ?\>
Glad you got the PHP version working!
Not sure about the Python version. I’ve found this tool to be pretty useful for tracking down these kinds of problems: http://requestb.in/
You can temporarily change the GameThrive API urls to requestbin and see if there are any differences between your PHP and Python version.
Thanks for posting FearTec, useful head start.
Hi I’m using FearTec PHP code and just changed it to work with segments, as I want to notify all users and I get this error:
string(49) "{“errors”:[“Segments require a valid auth key.”]}"
I am using the REST API KEY that’s in my app settings page, so not sure why I am getting that error. Maybe I need to set up something else inside Gamethrive?
Any ideas?
This is the code:
\<?php $ch = curl\_init(); curl\_setopt($ch, CURLOPT\_URL, "https://gamethrive.com/api/v1/notifications"); curl\_setopt($ch, CURLOPT\_HTTPHEADER, array("Authorization: Basic my-rest-api-key-from-app-settings-page")); curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, TRUE); curl\_setopt($ch, CURLOPT\_HEADER, FALSE); curl\_setopt($ch, CURLOPT\_POST, TRUE); curl\_setopt($ch, CURLOPT\_POSTFIELDS, "{\"app\_id\":\"my-app-id-from-app-setting-page\",\"isIos\": false,\"isAndroid\":true,\"included\_segments\": [\"All\"],\"contents\": {\"en\":\"Hello World 3\"}}"); curl\_setopt($ch, CURLOPT\_HTTPHEADER, array("Content-Type: application/json")); curl\_setopt($ch, CURLOPT\_SSL\_VERIFYPEER, false); $response = curl\_exec($ch); curl\_close($ch); var\_dump($response); ?\>
That looks about right. Maybe try removing the part that sets CURLOPT_HEADER to false?
If that doesn’t work, could you try using RequestBin (http://requestb.in/) to check what’s getting sent and paste the ouput here?
Hi,
Following george18 advice used requestb.in and looked like the only header sent was the content-type, found out that only the last header will be caught hence changed the code to this and now it works:
\<?php $ch = curl\_init(); curl\_setopt($ch, CURLOPT\_URL, "https://gamethrive.com/api/v1/notifications"); $headers = array( 'Content-type: application/json', 'Authorization: Basic my-rest-api-key-from-app-settings-page', ); curl\_setopt($ch, CURLOPT\_HTTPHEADER, $headers); curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, TRUE); curl\_setopt($ch, CURLOPT\_HEADER, FALSE); curl\_setopt($ch, CURLOPT\_POST, TRUE); curl\_setopt($ch, CURLOPT\_POSTFIELDS, "{\"app\_id\":\"my-app-id-from-app-setting-page\",\"isIos\": false,\"isAndroid\":true,\"included\_segments\": [\"All\"],\"contents\": {\"en\":\"Hello World 3\"}}"); curl\_setopt($ch, CURLOPT\_SSL\_VERIFYPEER, false); $response = curl\_exec($ch); curl\_close($ch); var\_dump($response); ?\>
Changing CURLOPT_HEADER to false did not affect.
Thank for the advice !