如何解决无法使用Python代码列出GSuite域中的组织单位
我正在尝试列出GSuite域中的所有组织单位,但是我无法正确访问资源对象。结果得到一个HttpRequest对象地址。这是我的代码:
from __future__ import print_function
from apiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from httplib2 import Http
from oauth2client.client import flow_from_clientsecrets
import pickle
import os.path
import requests
import json
from oauth2client.file import Storage
from oauth2client.tools import run_flow
ID = "xyz" # mycostomer id
scope = ["https://www.googleapis.com/auth/admin.directory.group.readonly","https://www.googleapis.com/auth/admin.directory.groups","https://www.googleapis.com/auth/admin.directory.group.member","https://www.googleapis.com/auth/admin.directory.user","https://www.googleapis.com/auth/admin.directory.users.userKey","https://www.googleapis.com/auth/admin.directory.orgunit"]
json_secret = "secret.json"
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle','rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
json_segreto,scope)
creds = flow.run_local_server(port=0)
with open('token.pickle','wb') as token:
pickle.dump(creds,token)
service = build('admin','directory_v1',credentials=creds)
ou = service.orgunits().list(customerId=ID)
print(ou)
我要去哪里错了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。