I need to start crawling this url: https://sites.google.com/a/domain.com/sites/system/app/pages/meta/domainIndex using python script.
How to authorize this Google Site URL using OAuth2.0 with Service Account.
In the case of OAuth1.0, We have send the request to https://www.google.com/accounts/ClientLogin and extract the token which received as a token and authorized the url.
OAuth 1.0 Authenication
url = 'https://www.google.com/accounts/ClientLogin'
request = urllib.urlencode({
'accountType': 'HOSTED',
'Email': '[email protected]',
'Passwd': 'userPassword',
'service': 'jotspot'})
#.. Fetch the url: https://www.google.com/accounts/ClientLogin and extract the token
headers = {
'Authorization': 'GoogleLogin auth=' + token,
'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15 ( .NET CLR 3.5.30729)',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Host': 'sites.google.com',
'Connection': 'keep-alive'
}
# .. Fetch the Google Site url with below headers
Some time ago I wrote a class for myself to handle OAuth2 authentication with Google APIs. It might serve as an example for you. And, yes, you need to register an "application", but that is just to get the client id/secret.
Some notes:
The class uses the 'offline' access type to obtain credentials that can be stored and re-used in the future.
The
settings
variable holds an instance of a class storing all my settings, in this case, the previously obtained google api credentials.GAuthDialog
is a dialog that presents the user with user/password login and reads the code google produces.The
execute
method wraps any method that requires access to the API and authentication.The class can be used as follows, e.g. for google drive:
and then we have:
And here comes the code of the class: