mikusai
September 5, 2024, 6:54pm
1
I am attempting to upload an SGF file to my library using the API. the code I have so far:
<?php
$tokken = "SECRETACCESSTOKEN";
$sgf = "(;GM[1]SZ[13]KM[7.0]RU[Chinese]
PB[Player1(870)]
PW[Player2(1554)]
;B[dd];W[kd];B[dj];W[jk];B[id];W[jc];B[ic];W[fd];B[ec];W[fc];B[df];W[ff];B[hk];W[ik];B[hj];W[ej];B[dk];W[fj];B[jg];W[ki];B[ig];W[dh];B[ch];W[cg];B[dg];W[ci];B[bh];W[di];B[bi];W[cj];B[ck];W[bj];B[bg];W[bk];B[cl];W[bl];B[fk];W[ek];B[el];W[fl];B[gk];W[em];B[dl];W[cm];B[gl];W[dm];B[hh];W[fh])";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://online-go.com/v1/me/games/sgf/11729");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, array("Authorization: Bearer " . $tokken));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'file=' . $sgf);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>
but sadly that does not work. any help would be greatly appreciated!
thanks in advance,
mikusai
b4ux1t3
September 6, 2024, 12:17am
2
I myself have been struggling authenticating through the api, what token did you use? I haven’t found a place in the app to retrieve an access token. I’ll dredge up a link to my post, in case it’s helpful to you.
Edit:
I’ve tried everything I can think of, and nothing seems to make this work.
I’ve tried everything in this post , and anything else I can get my hands on. Finally, I tried a curl command, and I’m getting something new:
{"error": "unsupported_grant_type"}400
Here’s my curl (sanitized, obviously):
curl -X POST -d 'password={}&client_id={}j&username=b4ux1t3&grant_type=password' -vi -w "%{http_code}" -L https://beta.online-go.com/oauth2/token
Am I missing something obvious here?
EDIT: For the rec…
Does this look like the kind of error you’re getting?
mikusai
September 6, 2024, 3:10pm
3
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://online-go.com/oauth2/token/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'client_id=MYCLIENTID&grant_type=password&username=MYOGSUSERNAME&password=MYOGSPASSWORD');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/x-www-form-urlencoded"
));
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response, true);
echo $json['access_token'];
this is how I get my token. this part works, but the SGF upload script I have in the first post does not =(
1 Like
b4ux1t3
September 6, 2024, 3:35pm
4
Well, that’s disappointing, though I will say that you just solved my problem; I hadn’t been setting the header for my content type.
I’m going to poke at the SGF upload endpoint for a little while to see if I can offer any insights.
1 Like
mikusai
September 6, 2024, 3:47pm
5
even if you can’t find a way to make my code work, If you can find any way to upload sgf data at all it would be super helpful. doesn’t have to be in PHP format Im willing to try other ways. mostly I just need some code that actually works lol.
2 Likes
well, after quite a bit more searching it appears I need a “sessionid” cookie in the header as far as I can tell. but I don’t see where I am supposed to get it from. any ideas?