How we can give access or user permissions to a google docs link to share with others with PHP?

I am trying to give user permissions to google docs file using php with google docs api but I am getting scopes error and permissions error. It is giving errors while using insert and create permissions methods.
can you please share me the code, how to give user permission to the google docs file to share with others using PHP code and which type of scopes and services I have to use.

Google SDK API – update Workspace user profile data by service account (Not Authorized to access this resource/api)

I am trying to sync our user profiles from our internal SaaS to Google Workspace user profiles. Especially (gender, phone, jobTitle, department).
After a long reading, I found out that it is not possible to do by OAuth in the Google cloud project, but it is necessary to create a service account. I have created it, but I am still getting responses Not Authorized to access this resource/api.