I’m playing around with the APIs in Python, and it’s been a struggle, so I thought I’d post a summary of where I’ve got to, and then ask for help
The documentation is incomplete and out of date. There are some helpful people and posts, like @walken and @flovo and @anoek and especially @ben1182367 whose code I mostly copied. They have made it work, but it won’t hurt to have another example here. You can find other methods of doing this in the forums, but the below seems to be the current way that works.
Step 1 is to go here: Play Go at online-go.com! | OGS
and create a new application. “Authorization Grant Type” should be “Resource owner password based”. Copy the Client ID and the Client password from this screen, before you click save.
The below is my code for the rest of the process (so far). Paste in your username,password,clientId and
clientpassword at the top, and then in the emit statements, paste in userid (4 times), gamenumber (twice), and the move you want to make. Note that for the move co-ordinates, the letter i does exist i this format, and aa means A19 (for a 19x19 game)
import socketio
import requests
s = requests.Session()
username='my-username-from-ogs'
password='my-normal-password-that-I-use-for-ogs'
ClientID='as-copied'
ClientSecret='as-copied'
response=s.post('https://online-go.com/oauth2/token/',data={"grant_type":"password","username":username,"password":password,"client_id":ClientID,"client_secret":ClientSecret})
result=response.json()
token=result['access_token']
auth = requests.get('https://online-go.com/api/v1/ui/config', headers={'Authorization': 'Bearer {}'.format(token)}).json()
socket = socketio.Client(reconnection_delay_max=60, logger = True, engineio_logger=False)
socket.connect("https://online-go.com/socket.io/?EIO=3", headers={'Authorization': 'Bearer {}'.format(token)}, transports='websocket')
socket.emit("notification/connect", data={"auth": auth['notification_auth'],
"player_id": my-user-id,
"username": "my-username"})
socket.emit("chat/connect", data={"auth": auth['chat_auth'],
"player_id": my-user-id,
"username": "my-username"})
socket.emit("authenticate", data={"auth": auth['chat_auth'],
"player_id": my-user-id,
"username": "my-username"})
socket.emit("game/connect", data={"game_id": 46368391,
"player_id": my-user-id,
"chat": False})
socket.emit("game/move", data={"game_id": 46368391,
"player_id": my-user-id,
"move": "my-move"})
So this does post a move in the game for me (most of the time). You can turn either of the loggers on to see data that might hep (but that seems to stop it working sometimes?). Where I am stuck now is receiving a move from the server, when my opponent makes a move.
I have tried all combinations that I can thnk of from other examples on the forum, and on the internet, but nothing has worked.
I don’t underatnd this socketio stuff very well. Why does this code keep running after it has made the move? Is that expected?
Maybe a more reliable way would be to collect the full game state every second, and work out whether there has been a move myself. That seems wasteful though.