问题描述
我正在尝试使用python创建一个服务帐户,以供Google Calendar API在无需先登录的情况下将自己的日历显示到网站。
这是我到目前为止所拥有的:
ScopES = ['https://www.googleapis.com/auth/sqlservice.admin']
SERVICE_ACCOUNT_FILE = os.path.join(os.path.dirname(
os.path.realpath(__file__)),'static/calendarSync/service-account.json')
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE,scopes=ScopES)
google_account = googleapiclient.discovery.build(
'calendar','v3',credentials=credentials)
service = google_account.__init__()
为了调用API提供的相同方法(calendarList等),我需要执行init吗? 如果是这样,我将如何填写以下参数:self,http,baseUrl,model,requestBuilder,developerKey,resourceDesc,rootDesc,schema?如果不是,如何调用该对象的日历方法?
解决方法
您可能想看看带有Python快速入门here的日历
因此,例如要获取日历列表,您必须首先构建Calendar服务,如下所示:
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.animation as animation
def create_plot():
n=500
x1 = np.random.normal(loc=0.0,scale=1,size=n)
x2 = np.random.gamma(2.5,2,size=n)
x3 = np.random.exponential(3.5,n)+8
x4 = np.random.uniform(-2.5,5,size=n)
arts = []
gspec = gridspec.GridSpec(2,2)
topleft_histogram = plt.subplot(gspec[0,0])
topright_histogram = plt.subplot(gspec[1:,0])
lowerleft_histogram = plt.subplot(gspec[0,1:])
lowerright_histogram = plt.subplot(gspec[1:,1:])
y1 = topleft_histogram.hist(x1,density=True,bins=100)
y2 = topright_histogram.hist(x2,bins=100)
y3 = lowerleft_histogram.hist(x3,bins=100)
y4 = lowerright_histogram.hist(x4,bins=100)
arts = [y1,y2,y3,y4]
return arts ## return the artists created by `plt.plot()`
create_plot()
此外,请记住,您必须执行域范围的委派,以获得预期的结果。