Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Google API OAuth v2 Python
#1
I have been trying to find a way to automate blogger Post, i was able to access normal data of my blog with a API Key, For Posting I need to have a OAuth v2 authorization I didnt find any good tutorial/sample code for this.

i found this page which is quite similar to what to do but it require a manual copy/paste of authorize code
http://www.datadependence.com/2016/03/go...ry-oauth2/

import requests
from apiclient.discovery import build
import oauth2client
from oauth2client import file
import apiclient.discovery
import webbrowser
import httplib2

Key = "hidden"
BlogId = "hidden"
Scope = "https://www.googleapis.com/auth/blogger"


blog = build('blogger','v3', developerKey=Key)

def get_credentials():
    """Gets google api credentials, or generates new credentials
    if they don't exist or are invalid."""

    flow = oauth2client.client.flow_from_clientsecrets(
        'client.json', Scope,
        redirect_uri='urn:ietf:wg:oauth:2.0:oob')
    storage = oauth2client.file.Storage('credentials.dat')
    credentials = storage.get()
     
    if not credentials or credentials.invalid:
        auth_uri = flow.step1_get_authorize_url()
        webbrowser.open(auth_uri)
        auth_code = input('Enter the auth code: ')
        credentials = flow.step2_exchange(auth_code)
     
        storage.put(credentials)
     
    return credentials
 
def get_service():
    """Returns an authorised blogger api service."""
    credentials = self.get_credentials()
    http = httplib2.Http()
    http = credentials.authorize(http)
    service = apiclient.discovery.build('blogger', 'v3', http=http)

    return service
does anyone know any resource/tutorial to Oauth v2, Google api and python intergration for automate the blog posting.....??
Reply


Messages In This Thread
Google API OAuth v2 Python - by oneclick - Sep-09-2019, 05:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New on python. Needs help with Google sheet jeromep 1 161 Apr-25-2024, 06:47 PM
Last Post: deanhystad
  (Python) Pulling data from UA Google Analytics with more than 100k rows into csv. Stockers 0 1,247 Dec-19-2022, 11:11 PM
Last Post: Stockers
  Deploy Python to Cloud and save output to Google Drive chandrabr80 2 1,594 Jan-25-2022, 06:56 AM
Last Post: ndc85430
  install apache-airflow[postgres,google] on Python 3.8.12 virtual env ShahajaK 1 7,903 Oct-07-2021, 03:05 PM
Last Post: Larz60+
  understanding Google's OAuth 2.0 aster 0 1,718 Apr-18-2021, 12:54 PM
Last Post: aster
  how to import files in Google Collab wihout downloading them to PC and to Google Disk sveto4ka 9 3,951 Jun-03-2020, 12:40 PM
Last Post: sveto4ka
  PYTHON - GOOGLE... create new spreadsheet? danclark81 3 2,708 Feb-02-2020, 08:57 PM
Last Post: danclark81
  Implementing OAuth 2 ( 2-legged) krishnanunnik 2 2,155 Sep-16-2019, 11:13 AM
Last Post: krishnanunnik
  How do I install apps from google play store? using python + selenium.. mongo 0 2,289 Aug-05-2019, 12:41 AM
Last Post: mongo
  Linking python to Google Sheets Charliefish1311 1 2,300 Jul-09-2019, 12:31 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020