I'm using gdata-python-client
to access the Google Domain Shared Contacts API.
In enterprise applications you may want to programmatically access users data without any manual authorization on their part.
There was a protocol called 2LO (2 legged OAuth), but seems like it was linked to OAuth1 which was deprecated: "Important: OAuth 1.0 is deprecated, and registration of new OAuth 1.0 clients is closed." is all over the Oauth1 docs.
There is a new OAuth2 based recipe for "Domain-wide Delegation of Authority":
In Google Apps domains, the domain administrator can grant to third party applications domain-wide access to its users' data — this is referred as domain-wide delegation of authority. To delegate authority this way, domain administrators can use service accounts with OAuth 2.0.
This works with google-api-python-client
but not with gdata-python-client
.
Question: Is there any way to achieve this with Python? Seems like code from the gdata client is prehistoric - is there any other GAE runtime with a modern client library supporting delegation for the data APIs?
[update]
If I sign an httplib2 connection and call the Atom endpoint at I'm able to retrieve the feed.
http = httplib2.Http()
http = credentials.authorize(http)
resp, content = http.request(
'https://www.google.com/m8/feeds/contacts/default/full', 'GET'
)
Unfortunately gdata-python-client
uses httplib instead of httplib2.
[solved]
Perhaps I'm missing some step but looks like the token is not valid until we perform a call using httplib2. I have to run the above code BEFORE running the sample given in [aeijdenberg]'s answer, otherwise I get a 401.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…