Blogger API with python fully and easily - free source code

Lib :

pip install httplib2
pip install google-api-python-client
pip install oauth2client

Source code :

import httplib2
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from import run_flow
from googleapiclient import discovery

# Start the OAuth flow to retrieve credentials
def authorize_credentials():
    CLIENT_SECRET = 'client_secret.json'
    SCOPE = ''
    STORAGE = Storage('')
    # 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

# print(credentials)
def getBloggerService():
    credentials = authorize_credentials()
    http = credentials.authorize(httplib2.Http())
    discoveryUrl = ('$discovery/rest?version=v3')
    service ='blogger', 'v3', http=http, discoveryServiceUrl=discoveryUrl)
    return service

def postToBlogger(payload):
    service = getBloggerService()
    print("Done post!")
    return insert

def buildHtml():
    html = '<h1>Hello world</h1>'
    return html

title = "Testing post 2" 

# print(htmlData)

customMetaData = "This is meta data"
        "content": buildHtml(),
        "title": title,
        'labels': ['label1','label2'],
        'customMetaData': customMetaData

Posting Komentar

Lebih baru Lebih lama