使用 Soup (Vala) 在 Google Drive API 中出现错误 "may be sending automated queries"

Get error "may be sending automated queries" in Google Drive API using Soup (Vala)

Google 驱动 API 有时 returns 一个 HTML 页面的响应,内容为:

<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Sorry...</title>
    <style>
        body {
            font-family: verdana, arial, sans-serif;
            background-color: #fff;
            color: #000;
        }
    </style>
</head>

<body>
    <div>
        <table>
            <tr>
                <td><b>
                        <font face=sans-serif size=10>
                            <font color=#4285f4>G</font>
                            <font color=#ea4335>o</font>
                            <font color=#fbbc05>o</font>
                            <font color=#4285f4>g</font>
                            <font color=#34a853>l</font>
                            <font color=#ea4335>e</font>
                        </font>
                    </b></td>
                <td style="text-align: left; vertical-align: bottom; padding-bottom: 15px; width: 50%">
                    <div style="border-bottom: 1px solid #dfdfdf;">Sorry...</div>
                </td>
            </tr>
        </table>
    </div>
    <div style="margin-left: 4em;">
        <h1>We\'re sorry...</h1>
        <p>... but your computer or network may be sending automated queries. To protect our users, we can\'t process
            your request right now.</p>
    </div>
    <div style="margin-left: 4em;">See <a href="https://support.google.com/websearch/answer/86640">Google Help</a> for
        more information.<br /><br /></div>
    <div style="text-align: center; border-top: 1px solid #dfdfdf;"><a href="https://www.google.com">Google Home</a>
    </div>
</body>

</html>

当使用参数“?alt=media”调用 https://www.googleapis.com/drive/v3/files/file_id 端点以获取文件内容时,会发生这种情况。

我没有超出任何配额。

我在其他调用中没有遇到此错误,例如 https://www.googleapis.com/drive/v3/files?q=trashed = False .

错误发生在我用 Vala (https://github.com/bcedu/VGrive) 编写的应用程序中。此应用程序运行良好,没有出现此错误。当 Google 更改身份验证时,它开始出现,而不是在查询参数中使用访问令牌,而是使用 HTTP header。我进行了此更改并在某些请求中解决了问题(如我提到的搜索文件),但当我想下载文件时仍然遇到错误。

我正在使用 Google 驱动器 api v3

我正在使用 vala 库 Soup(一个众所周知的 Gnome 库 https://developer.gnome.org/libsoup/unstable/)来发出请求。您可以使用以下代码测试错误:


public static int main(string[] args) {
    // THIS DOESNT WORKS
    string method = "GET";
    string file_id = "";  // Some Google Drive File ID
    string uri = "https://www.googleapis.com/drive/v3/files/%s?alt=media".printf(file_id);
    string access_token = "";  // A valid acces_token

    Soup.Session session = new Soup.Session ();
    Soup.Message message = new Soup.Message (method, uri);

    message.request_headers.append("Authorization", "Bearer %s".printf(access_token));
    session.send_message (message);

    // Response is stored in message.response_body.data
    print("AUTOMATED QUERY ERROR:\n"+(string)message.response_body.data+"\n\n");


    // THIS WORKS
    uri = "https://www.googleapis.com/drive/v3/files?q=trashed = False and 'root' in parents";
    session = new Soup.Session ();
    message = new Soup.Message (method, uri);

    message.request_headers.append("Authorization", "Bearer %s".printf(access_token));
    session.send_message (message);

    // Response is stored in message.response_body.data
    print("THIS WORKS, SO TOKEN IS PASSES CORRECTLLY...\n"+(string)message.response_body.data+"\n");


    return 0;
}


运行 测试:

valac --pkg libsoup-2.4 GoogleTest.vala
./GoogleTest

您需要安装:

我希望得到成功响应或身份验证错误,但不会看到 html 页面说我正在进行自动查询。它是一个 API,它应该被应用程序使用,而不仅仅是人类。

我是否遗漏了 google 驱动器 API 中的某些内容?我是否必须执行额外的步骤才能通过 Soup 传递不记名令牌?

正如评论中所讨论的,问题正在 google 论坛中进行跟踪。 https://issuetracker.google.com/153717392

那里的问题似乎已经解决,OP 使用 API 不再有问题。