Trouble making authenticated calls to Google API via OAuth

前端 未结 2 995
傲寒
傲寒 2021-01-24 14:12

When I try to make a call to the Google Directory API using Server to Server authentication, I get the error message \"Not Authorized to access this resource/api\".

What

2条回答
  •  渐次进展
    2021-01-24 14:51

    I found by trial and error that removing "admin." from the scopes makes it work (in addition to everything said above about following these steps: https://developers.google.com/drive/web/delegation#delegate_domain-wide_authority_to_your_service_account ).

    $cs = json_decode(file_get_contents( . 'client_secrets.json'), true); 
    $cs = $cs['web'];
    $cred = new Google_Auth_AssertionCredentials(
        $cs['client_email'], //why do they call this "service account name" ? Misleading >:(
        array(
            'https://www.googleapis.com/auth/directory.user',
            'https://www.googleapis.com/auth/directory.group',
            'https://www.googleapis.com/auth/directory.group.member'
        ),
        $key,
        'notasecret',
        'http://oauth.net/grant_type/jwt/1.0/bearer',
        '' //_my_ email as an user with admin rights
    );
    

提交回复
热议问题