Trying to upload an SGF but it doesn't work. Please help!

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

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:

Does this look like the kind of error you’re getting?

$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

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

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?