All right, this is a ghetto answer because I'm not satisfied with it at all since I don't really understand what's going on, but maybe it will help people, so here goes..
I'm using the ruby google_drive gem, just trying to download all the worksheets in my spreadsheet as CSV. In order to do this, I have to convert from the encoded GID (I've seen it called 'WID') to the real GID. Before, my wid_to_gid method looked like this (documented from other answers here on stack overflow):
def wid_to_gid(wid)
wid.to_i(36) ^ 31578
end
In order to handle the 7-digit WIDs, I changed it to this:
def wid_to_gid(wid)
wid_val = wid.length > 3 ? wid[1..-1] : wid
xorval = wid.length > 3 ? 474 : 31578
wid_val.to_i(36) ^ xorval
end
So.. a couple things going on here.. I realized that (at least on my spreadsheet), for the 7-digit WIDs, I could get the GID by dropping the first character, converting to base 36 number and then XORing with 474 (no idea why this magic number.. sorry).
If the WID is only 3 digits, then the old transform works (as has been detailed in many other answers on stack overflow).
For the spreadsheet I was working with, it had 3 worksheets. Here are the WIDs and GIDs of each:
GID - WID
0 - od6
2019719111 - oxehkwt
1506531046 - oowy6v0
I really just wanted to get this done so I didn't spend more time investigating once I got it to work. Would appreciate it if others can verify/reject this code as working or not for them... and if it doesn't work, maybe it will at least give you some ideas!