You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Google Drive API请求中的自身userId以复用TiddlyDrive代码?

问题:获取TiddlyDrive所需的userId(SOME_DIGITS)

我正在复用TiddlyDrive的代码,手动复现流程以理解逻辑,但无法获取自身的userId。该代码通过以下格式的URL访问Google Drive中的HTML文件:

tiddlydrive.github.io/?state={ids:[THE_ID_OF_A_FILE],action:open,userId:SOME_DIGITS,resourceKeys:{}}

其中THE_ID_OF_A_FILE可从Google Drive打开文件后的浏览器地址栏获取,但我找不到对应的userId(即SOME_DIGITS):调用Drive.About.get()获取的permissionId与该值不符,GCP项目的clientID也不匹配。

若使用另一Google账号的正确文件ID,但沿用原账号的SOME_DIGITS作为userId访问如下URL时,会触发错误:

tiddlydrive.github.io/?state={ids:[THE_CORRECT_ID_OF_ANOTHER_FILE_FOR_ANOTHER_ACCOUNT],action:open,userId:SOME_DIGITS,resourceKeys:{}}

错误提示:

There was an error downloading the file.

该错误对应index.html中id为"error-msg"的提示,由代码的catch分支触发(即便已授权代码访问Google Drive),相关代码片段如下:

function fetch_file() {
        var state = JSON.parse(getParameterByName('state'));
        if (state == null) {
            $('#loader').hide();
            $('#nofile-msg').show();
            $('#content').hide();
            return;
        }
        gapi.client.drive.files.get({
            'fileId': state.ids.pop(),
            'alt': 'media'
        }).then(function(file) {
            if (needLegacySrc()) {
                $('#content')[0].contentWindow.document.open('text/html', 'replace');
                $('#content')[0].contentWindow.document.write(file.body);
                $('#content')[0].contentWindow.document.close();
            } else {
                $('#content')[0].srcdoc = file.body;
            }
            setupSaver();
            $('#loader').hide();
        }).catch(function(err) {
            $('#loader').hide();
            $('#error-msg').show();
        });
    }

请问如何获取自身的userId/SOME_DIGITS?我的最终目标是复用该代码以打开Google Drive中的TiddlyWiki HTML文件,仅作私人使用,无需发布到Workspace Marketplace。

内容的提问来源于stack exchange,提问作者seb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 07:05:05