Google云端服务帐户和“未经授权的客户端或请求范围”

I am trying to upload files to a Google Drive account via a service call using the Google_Client.php class sample from the Google Developer Console. 2 months ago I did this successfully using a service account set up in the Developer Console, and a Google Drive account previsouly set up.

I am now trying to do the same thing with a new service account and Drive account, but I get the error in the title. As far as I can tell I'm doing everything the same. My research suggests that I need to give the service account email addres access to a directory on Google drive, but I can't find out for the life of me how to do that.

The only reason I can imagine that this worked the first time I did this is that for that account I first set it up as a web application rather than a service account, and used the consent screen a my browser to approve the Drive account access.

BTW - I have checked other similar posts on stackoverflow, and none have helped. Cross fingers for this post.

Turns out the simplest way to allow your google api project access to your drive account is to follow the simple steps here for setting up a simple html page that displays a consent button for giving access to the drive account: https://developers.google.com/drive/web/quickstart/quickstart-js

You just have to run the quickstart sample once, then if you go to your google drive account, click settings->manage apps. Scroll to the bottom of the list and you should see your google api project.

Now you will be able to do service calls with the api to access your google drive account.