Solserv Posted July 17, 2018 Share Posted July 17, 2018 Hello, I recently develop a game in html5 and upload it to run on telegram. But I am not able to use the function setgamescore to submit the score on telegram server. I am using Ajax to post the score. Please If any one had any idea what I am doing wrong. Please help. Thank you Quote Link to comment Share on other sites More sharing options...
AndyTyurin Posted July 17, 2018 Share Posted July 17, 2018 Man, if you want to get a specific answer, show your code to us first, otherwise I can say: "just to solve it" Quote Link to comment Share on other sites More sharing options...
Solserv Posted July 17, 2018 Author Share Posted July 17, 2018 This is the code I am using in my game to send the score to telegram and I am 400 error bad request. var api_url = "https://api.telegram.org/bot"; var token = "593511496:AAFE92jjNdWSsWfUMT8PCSAqmOVYCohqzBc"; api_url += token; var userId; var chatId; var messageId; var xhttp = new XMLHttpRequest(); function init() { console.log (window.TelegramGameProxy.initParams); userId = parseInt(window.TelegramGameProxy.initParams.userId); chatId = parseInt(window.TelegramGameProxy.initParams.chatId); messageId = parseInt(window.TelegramGameProxy.initParams.messageId); console.log (userId); console.log (chatId); console.log (messageId); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { var data = JSON.parse(this.responseText); console.log (data); } } api_url = api_url + "/setGameScore?user_id=" + userId + "&chat_id=" + chatId + "&message_id=" + messageId + "&score=" + score + "&inline_message_id="; console.log (api_url); xhttp.open ( "POST", api_url, true); xhttp.send(); } Hope this will be helpful for you. Thanks Quote Link to comment Share on other sites More sharing options...
AndyTyurin Posted July 17, 2018 Share Posted July 17, 2018 First I will focus your attention to 400, you didn't make right request to server, it's not a server-side problem. Then mean that you did a mistake on your request. Try to add onerror in your code to detect the error itself. Quote Link to comment Share on other sites More sharing options...
Solserv Posted July 17, 2018 Author Share Posted July 17, 2018 I tried the same code with get me function that return some basic information. It works successfully. Also when I tried the onerror. It display bad request. You are saying that request is not proper to reach out. Quote Link to comment Share on other sites More sharing options...
AndyTyurin Posted July 17, 2018 Share Posted July 17, 2018 12 hours ago, Solserv said: I tried the same code with get me function that return some basic information. It works successfully. Also when I tried the onerror. It display bad request. You are saying that request is not proper to reach out. I didn't say to reach out, just it's not right, it also can be because of bad parameters which server-side can't handle or accept. Did you try to post JSON data instead of query? Did you try to use GET method? Quote Link to comment Share on other sites More sharing options...
Solserv Posted July 17, 2018 Author Share Posted July 17, 2018 No I didn't try the get method. I will try to send the data in json format and use the get method. Hope this will resolve the issue. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
AndyTyurin Posted July 17, 2018 Share Posted July 17, 2018 Yes, but try to use POST with JSON and GET with queries. Hopefully it will help you, write if not. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.