Google <<
Previous Next >> Youtube
Blogger
https://cycuorg.blogspot.com/
利用 Blogger API 讓 Pelican Blog 與 Blogger 資料同步.
https://mde.tw/lab/blog/sync-pelican-and-blogger-content.html
從https://console.cloud.google.com 取得 json 格式的 secret 檔案後, 利用下列程式登入管理者帳號授權後, 將 json 資料轉為 data 格式, 之後的 Desktop 程式就可利用 data 格式的授權, 透過 Blogger API 管理與 secret 對應授權的 Blogger 網誌.
Python 可攜系統中與 Google API 相關模組與版本參考:
pip install google-api-python-client oauth2client google_auth_oauthlib google-auth
google-api-core 1.28.0
google-api-python-client 2.6.0
google-auth 1.30.1
google-auth-httplib2 0.1.0
google-auth-oauthlib 0.4.4
googleapis-common-protos 1.53.0
oauth2client 4.1.3
oauthlib 3.1.1
blogger_secret_convert_to_token.py
# get secrets: https://console.developers.google.com
# https://developers.google.com/blogger/docs/3.0/using
# pip install google_auth_oauthlib
# under Mac command + b to execute
import pickle
import os
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
SCOPES = ['https://www.googleapis.com/auth/blogger', ]
# we check if the file to store the credentials exists
if not os.path.exists('yen_cycu_blogger_token.dat'):
flow = InstalledAppFlow.from_client_secrets_file('yen_cycu_blogger_secrets.json', SCOPES)
credentials = flow.run_local_server()
with open('yen_cycu_blogger_token.dat', 'wb') as credentials_dat:
pickle.dump(credentials, credentials_dat)
else:
with open('yen_cycu_blogger_token.dat', 'rb') as credentials_dat:
credentials = pickle.load(credentials_dat)
service = build('blogger', 'v3', credentials=credentials)
print(service)
參考資料:
Google API Python client: https://pypi.org/project/google-api-python-client/
Google Authentication library: https://pypi.org/project/google-auth-oauthlib/
Google <<
Previous Next >> Youtube