how to access drive as certain google user

2019-09-02 09:09发布

I am using appengine( python) and trying to manage a shared google drive directory for certain user. Can my program always access the drive without to go to authorize page, even when I am login as different user. Say I login 123 but I want to access abc's google drive all the time.

2条回答
可以哭但决不认输i
2楼-- · 2019-09-02 09:51

You can do this through domain wide delegation for Google Apps users: https://developers.google.com/drive/delegation, though the domain admin will have to add your app for authorization.

If you want to create an app for the marketplace which will prevent the need for a manual setup, you can follow instructions here: https://developers.google.com/google-apps/marketplace/tutorial_python_gae#Integrate-OAuth

I don't think you can access any of Google's API if the user is not logged into your application even if you were previously granted access, at least from my understanding of the authentication methods available.

查看更多
在下西门庆
3楼-- · 2019-09-02 10:02

When the user adds a app engine project service account as a share, you can always access it, without the OAuth2 dance.

Your app engine project service account looks like : example@appspot.gserviceaccount.com You can find information here : https://developers.google.com/drive/service-accounts#google_app_engine_project_service_accounts

def _init_service_account(self):

    if os.environ['SERVER_SOFTWARE'].startswith('Development') :
        logging.warning('Service account not used in development')
        return None
    else :        
        SCOPE = 'https://www.googleapis.com/auth/drive'
        API_KEY = '.....'                                 # GAE
        credentials = AppAssertionCredentials(scope=SCOPE)
        logging.info('service account : ' + app_identity.get_service_account_name())
        http = credentials.authorize(httplib2.Http())
        return build('drive', 'v2', http=http, developerKey=API_KEY) 
查看更多
登录 后发表回答