你可以試試下面的解決方案。
請確保以下所有進口都在那裏。
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import flow_from_clientsecrets
from oauth2client.tools import run
設置你的client_secrets.json這樣
設置的client_secrets.json像
{
"web": {
"client_id": "[[INSERT CLIENT ID HERE]]",
"client_secret": "[[INSERT CLIENT SECRET HERE]]",
"redirect_uris": [],
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token"
}
}
對於未來的參考,你可以存儲在一個文件blogger.dat
證書更快的處理
FLOW = flow_from_clientsecrets(Path_to_client_secrets.json,scope='https://www.googleapis.com/auth/blogger',message=MISSING_CLIENT_SECRETS_MESSAGE)
storage = Storage('blogger.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run(FLOW, storage)
一旦證書都完成設置。它的時間發佈!所以我們創建一個httplib2.Http對象來處理我們的HTTP請求,並使用我們良好的證書對它進行授權。
http = httplib2.Http()
http = credentials.authorize(http)
service = build("blogger", "v2", http=http)
一旦完成我們所建立的博客體,並張貼
try:
body = {
"kind": "blogger#post",
"id": "6814573853229626501",
"title": "posted via python",
"content":"<div>hello world test</div>"
}
request = service.posts().insert(your_blogId_ID,body)
response = request.execute()
print response
except AccessTokenRefreshError:
print ("The credentials have been revoked or expired, please re-run the application to re-authorize")
希望這會有所幫助。
謝謝特拉維斯,我會試試這個,讓你知道結果.. – 2013-03-01 12:47:09
它是否適合你? – 2013-03-08 21:56:55