Spaces:
Running
Running
Update OAuth client secret and improve image upload handling in post_blog.py and get_refresh_token.py
733aa95
import httplib2 | |
from oauth2client.client import flow_from_clientsecrets | |
from oauth2client.file import Storage | |
from oauth2client.tools import run_flow | |
from googleapiclient import discovery | |
# Start the OAuth flow to retrieve credentials | |
def authorize_credentials(): | |
CLIENT_SECRET = 'client_secret.json' | |
SCOPE = 'https://www.googleapis.com/auth/blogger' | |
STORAGE = Storage('credentials.storage.json') | |
credentials = STORAGE.get() | |
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 | |
def getBloggerService(): | |
credentials = authorize_credentials() | |
http = credentials.authorize(httplib2.Http()) | |
discoveryUrl = ('https://blogger.googleapis.com/$discovery/rest?version=v3') | |
service = discovery.build('blogger', 'v3', http=http, discoveryServiceUrl=discoveryUrl) | |
return service | |
if __name__ == '__main__': | |
try: | |
getBloggerService() | |
except Exception as e: | |
print(str(e)) |