ValueError:客户端秘密必须用于网络或已安装的应用程序 - intion api to Google表
无论我尝试什么,我都会遇到这个错误。我是一个新手,只想将Google表与概念联系起来。如果有人能提供帮助,我将非常感谢。我将在下面包含代码。由于duh,被阻塞的数据被遮住了。 凭据 .json是Google表帐户凭据密钥。
我尝试了两个不同的资源来结合有效的东西,主要的是: ,如果有帮助。
一百万,感谢任何可以提供帮助的人。
from __future__ import print_function
import os.path
from googleapiclient.discovery import build
import pickle
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2 import service_account
from notion.client import NotionClient
from google.oauth2.credentials import Credentials
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SERVICE_ACCOUNT_FILE = 'credentials.json'
SAMPLE_SPREADSHEET_ID = 'OCCLUDED'
SAMPLE_RANGE_NAME = 'OCCLUDED'
NOTION_V2_TOKEN = "OCCLUDED"
creds = None
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
def get_sheet():
"""Shows basic usage of the Sheets API.
Prints values from a sample spreadsheet.
"""
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(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('sheets', 'v4', credentials=creds)
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
range=SAMPLE_RANGE_NAME).execute()
values = result.get('values', [])
if not values:
print('No data found.')
return None
else:
print('%s rows found.' % len(values))
return values
def get_prop_type(data):
# todo parse data to support types
return 'text'
def notion_update(data):
client = NotionClient(token_v2=NOTION_V2_TOKEN)
block = client.get_block(NOTION_PAGE_LINK)
cv = block.collection
rows = cv.get_rows()
cv.clear_properties()
for row in rows:
row.remove()
title = data[0][0]
cv.set_property('title', title, slug=title, property_type='title')
for i, prop in enumerate(data[0][1:]):
prop_type = get_prop_type(data[1][1:][i]) if data[1] and data[1][1:] else 'text'
cv.set_property(prop, prop, slug=prop, property_type=prop_type)
for row in data[1:]:
new_row = cv.add_row()
for i, value in enumerate(row):
prop = data[0][i]
new_row.set_property(prop, value)
if __name__ == '__main__':
data = get_sheet()
notion_update(data)
I'm running into this error no matter what I try. I am very much a newbie and just want to connect google sheets to notion. If anyone can help, I'd greatly appreciate it. I'll include the code below. Occluded data is occluded because duh.
credentials.json is the google sheets account credentials key.
I've tried two different sources to combine something that works, the main one being this:
https://github.com/aakashadesara/notion-google-sheets-sync, if it helps.
A million thanks to anyone who can help.
from __future__ import print_function
import os.path
from googleapiclient.discovery import build
import pickle
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2 import service_account
from notion.client import NotionClient
from google.oauth2.credentials import Credentials
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SERVICE_ACCOUNT_FILE = 'credentials.json'
SAMPLE_SPREADSHEET_ID = 'OCCLUDED'
SAMPLE_RANGE_NAME = 'OCCLUDED'
NOTION_V2_TOKEN = "OCCLUDED"
creds = None
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
def get_sheet():
"""Shows basic usage of the Sheets API.
Prints values from a sample spreadsheet.
"""
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(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('sheets', 'v4', credentials=creds)
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
range=SAMPLE_RANGE_NAME).execute()
values = result.get('values', [])
if not values:
print('No data found.')
return None
else:
print('%s rows found.' % len(values))
return values
def get_prop_type(data):
# todo parse data to support types
return 'text'
def notion_update(data):
client = NotionClient(token_v2=NOTION_V2_TOKEN)
block = client.get_block(NOTION_PAGE_LINK)
cv = block.collection
rows = cv.get_rows()
cv.clear_properties()
for row in rows:
row.remove()
title = data[0][0]
cv.set_property('title', title, slug=title, property_type='title')
for i, prop in enumerate(data[0][1:]):
prop_type = get_prop_type(data[1][1:][i]) if data[1] and data[1][1:] else 'text'
cv.set_property(prop, prop, slug=prop, property_type=prop_type)
for row in data[1:]:
new_row = cv.add_row()
for i, value in enumerate(row):
prop = data[0][i]
new_row.set_property(prop, value)
if __name__ == '__main__':
data = get_sheet()
notion_update(data)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论