【问题标题】:How to get the list of the account details using google my business api?如何使用 google my business api 获取帐户详细信息列表?
【发布时间】:2020-08-18 06:59:47
【问题描述】:

我正在尝试列出所有有权管理其帐户的帐户。但是当我使用https://mybusiness.googleapis.com/v4/accounts 时,它会显示(错误1),当我使用访问令牌时,它会提供用户帐户的详细信息,但我想列出所有帐户。但我不知道我该怎么做。 当我在 /accounts 上发送请求时,我的客户端 ID 作为不记名令牌,当我尝试不使用身份验证发送时,它会给出此错误

请求缺少所需的身份验证凭据。预期的 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据。见https://developers.google.com/identity/sign-in/web/devconsole-project

<html lang="en">
  <head>
    <script src="https://apis.google.com/js/platform.js" async defer></script>
    <script src="https://accounts.google.com/gsi/client" async defer></script>
    <script src="https://apis.google.com/js/client.js?onload=authorize"></script>
  </head>
  <body>
    <h2>prac</h2>
    <div
      id="g_id_onload"
      data-client_id="xxx.apps.googleusercontent.com"
      data-callback="handleCredentialResponse"
    ></div>
    <script>
      function handleCredentialResponse(response) {
        const config = {
          scope: "https://www.googleapis.com/auth/plus.business.manage",
          client_id: "xxx.apps.googleusercontent.com",
        };
        var requestOptions = {
          method: "GET",
          redirect: "follow",
        };

        fetch("https://mybusiness.googleapis.com/v4/accounts", requestOptions)
          .then((response) => response.text())
          .then((result) => console.log(result))
          .catch((error) => console.log("error", error));
        gapi.auth2.authorize(config, function (response) {
          var requestOptions = {
            method: "GET",
            redirect: "follow",
          };
          console.log(response.access_token);
          fetch(
            `https://mybusiness.googleapis.com/v4/accounts?access_token=${response.access_token}`,
            requestOptions
          )
            .then((response) => response.text())
            .then((result) => console.log(result))
            .catch((error) => console.log("error", error));
        });
      }
    </script>
  </body>
</html>

【问题讨论】:

  • 请编辑您的问题并包含您的代码。
  • @DaImTo 我已经添加了代码,如果可能,请提出任何解决方案

标签: javascript google-api google-my-business-api


【解决方案1】:

https://github.com/google/google-my-business-samples/blob/master/java/AccountsList.java 在这里你可以找到你的答案,结果是一个 JSONObject,你可以解析它。 记得在项目文件夹中包含你的 client_secrets.json 文件

【讨论】:

    猜你喜欢
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    相关资源
    最近更新 更多