【问题标题】:Re-seller API - insufficient permissions转销商 API - 权限不足
【发布时间】:2019-04-17 14:16:30
【问题描述】:

我正在尝试创建新客户并向客户附加 G-Suite 订阅,但似乎无法执行此操作。

我现在在哪里:

  • 可以创建 google 客户端对象
  • 可以检查该域是否已经存在客户
  • 可以创建客户对象

指南:

错误代码:

未捕获的 Google_Service_Exception: {"error":{"errors":[{"domain":"global","re​​ason":"insufficientPermissions","message":"Insufficient 权限"}]

我怀疑它与许可的范围有关(是的,我刚刚说过)。问题是我正在遵循谷歌的指南,所以我不确定问题出在哪里。

当前范围:

function get_client()
{
    $OAUTH2_SCOPES = [
        Google_Service_Reseller::APPS_ORDER,
        Google_Service_SiteVerification::SITEVERIFICATION,
        Google_Service_Directory::ADMIN_DIRECTORY_USER,
    ];

    $client = new Google_Client();
    $client->setApplicationName('test');
    $client->setScopes($OAUTH2_SCOPES);
    $client->setAuthConfig(__DIR__ . '/credentials.json');
    $client->setAccessType('offline');
    $client->setPrompt('select_account consent');

    // Load previously authorized token from a file, if it exists.
    // The file token.json stores the user's access and refresh tokens, and is
    // created automatically when the authorization flow completes for the first
    // time.
    $tokenPath = 'token.json';
    if(file_exists($tokenPath)) 
    {
        $accessToken = json_decode(file_get_contents($tokenPath), true);
        $client->setAccessToken($accessToken);
    }

    // If there is no previous token or it's expired.
    if($client->isAccessTokenExpired()) 
    {
        // Refresh the token if possible, else fetch a new one.
        if ($client->getRefreshToken()) 
        {
               $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
        } 
        else 
        {
            // Request authorization from the user.
            $authUrl = $client->createAuthUrl();
            printf("Open the following link in your browser:\n%s\n", $authUrl);
            print 'Enter verification code: ';
            $authCode = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

            // Exchange authorization code for an access token.
            $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
            $client->setAccessToken($accessToken);

            // Check to see if there was an error.
            if(array_key_exists('error', $accessToken))
            {
                throw new Exception(join(', ', $accessToken));
            }
        }
        // Save the token to a file.
        if (!file_exists(dirname($tokenPath))) 
        {
            mkdir(dirname($tokenPath), 0700, true);
        }
        file_put_contents($tokenPath, json_encode($client->getAccessToken()));
    }

    return $client;
}

【问题讨论】:

    标签: php google-admin-sdk google-workspace google-reseller-api


    【解决方案1】:

    我自己想出了解决办法。

    问题:
    权限不足

    解决方案:
    令牌文件未更新,新添加的权限 - 因此删除并重新创建 cred.json 文件 - 解决了问题:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-24
      • 2015-08-20
      • 2018-08-30
      • 2015-10-01
      • 2016-01-17
      • 1970-01-01
      相关资源
      最近更新 更多