Chiaming Yen's Cyber Universe

  • Home
    • SMap
    • reveal
    • blog
  • About
    • KMOL
    • MDE
    • ToDo
    • Google
      • Blogger
      • Youtube
  • Python
  • Portable
    • Lua 解譯
    • Wink
      • Add Wink
  • CMSiMDE
    • 建立網頁
    • 基本操作
      • 客製化
      • 編輯網頁內容
      • 上傳與引用檔案
      • 上傳與引用圖片
      • 嵌入程式碼
      • 嵌入影片檔
      • 檢視 STL
    • 置入 disqus
    • Gitlab 同步
    • Heroku 部署
    • Fossil SCM
    • 注意事項
      • 標題選擇
      • 靜態網頁 404
      • 動態網站錯誤
    • 延伸開發
    • 已知問題
      • IPv6
      • 上傳資料引用
      • MathJax
      • html 分頁
      • 靜態搜尋
      • template
      • 重複標題頁面
    • ajax
    • black
    • summernote
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

Copyright © All rights reserved | This template is made with by Colorlib