python - colab博主API授权
问题描述
使用这个脚本python-blogger-testting.py
import httplib2
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run_flow
from googleapiclient import discovery
CLIENT_SECRET = 'client_secret.json'
SCOPE = 'https://www.googleapis.com/auth/blogger'
STORAGE = Storage('credentials.storage')
# Start the OAuth flow to retrieve credentials
def authorize_credentials():
# Fetch credentials from storage
credentials = STORAGE.get()
# If the credentials doesn't exist in the storage location then run the flow
if credentials is None or credentials.invalid:
flow = flow_from_clientsecrets(CLIENT_SECRET, scope=SCOPE)
http = httplib2.Http()
credentials = run_flow(flow, STORAGE, http=http)
return credentials
credentials = authorize_credentials()
print(credentials)
def get_pages_from_jobs():
credentials = authorize_credentials()
http = credentials.authorize(httplib2.Http())
discoveryUrl = ('https://www.googleapis.com/blogger/')
service = discovery.build('blogger', 'v3', http=http, discoveryServiceUrl=discoveryUrl)
users = service.users()
# Retrieve this user's profile information
thisuser = users.get(userId='self').execute()
print('This user\'s display name is: %s' % thisuser['displayName'])
page=service.pages()
## onepage=page.get(blogId='xxxxxxxx',pageId='xxxxx').execute()
## print("this will show specific onepage", onepage)
## cities=['united states','India','Aus','brazil']
## for item in cities:
## title="title for "+item
## payload={
## "content": "<div dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\">\nEspeciallySports is a sports news portal aims at bringing the latest sports news for the fans that cover MMA, WWE, UFC, Cricket, Football, etc </div>\n",
## "title": title
## }
## respost=page.insert(blogId='xxxxx',body=payload,isDraft=False).execute() #publishing the new post
## print("printing the page id:",respost['id'])
payload={
"content": "<div dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\">\nEspeciallySports is a sports news portal aims at bringing the latest sports news for the fans that cover MMA, WWE, UFC, Cricket, Football, etc </div>\n",
"title": "ttile has been changed to uk"
}
respost=page.update(blogId='xxxxxx', pageId='xxxxxx', body=payload, publish=True).execute() #updating the existing post/page
get_pages_from_jobs()
不在 colab 中工作,他给了我授权链接,它返回令牌以重定向 URL,即本地主机:8090 但 Colap 从未获得令牌密钥......如何手动将密钥从 URL 复制到脚本?有什么帮助吗?有没有办法在 COLAB 中使用博客 API?
解决方案
推荐阅读
- c# - 将格式化值从 DataGridView 插入到数据库
- c# - 串行监视器、DataReceived 处理程序误解 C#、WPF
- java - 如何防止 Hibernate 在刷新时覆盖版本字段?
- android - 如何将数据从第一个活动显示到另一个活动或片段?
- jasper-reports - 在 Jasper 报告中使用多个数据源
- c# - 检测输入了哪个对撞机
- python - 构建子图
- flutter - 如何使用主题通用更改AppBar的文本颜色,FAB的图标颜色?
- node.js - 删除猫鼬模型上的引用 ID
- android - getActivity() 在视图寻呼机片段中返回 null