drddx3115 2018-11-14 15:03
浏览 51
已采纳

转销商API - 权限不足

I'm trying to create a new customer and attach a G-Suite subscription to the customer, but seem to be unable to do this.

Where am I currently:

  • Can create a google client object
  • Can check if a customer already exists with that domain
  • Can create a customer object

Guide:

Error Code:

Uncaught Google_Service_Exception: {"error":{"errors":[{"domain":"global","reason":"insufficientPermissions","message":"Insufficient Permission"}]

I suspected it has something to with the scope of the permission (yes really, I just said that). The thing is that I'm following the guide from google, so I'm not sure where the problem is.

Current Scope:

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:
%s
", $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;
}
  • 写回答

1条回答 默认 最新

  • dongyin2390 2018-11-15 09:30
    关注

    I manage to figure out the solution myself.

    The problem:
    insufficient Permissions

    The Solution:
    The token file wasn't updated, with the newly added permissions - so deleting and recreating the cred.json file - fixed the problem :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口