OAuth Python Example

Hi All,

Does anyone know of a Python example on how I can complete the OAuth
process with the FreeAgent API?

I have been using the Django code snippet at
https://djangosnippets.org/snippets/1353/. However, I am getting ‘module’
object has no attribute ‘OAuthConsumer’ from Line 20.

Thanks in advance,

Paul

Hi Graeme,

I have had a look at the link you sent and still haven’t the foggiest how
to utilise that information and make it work.

Do you know whether there is an example anywhere that will show me how to
do the OAuth request so I can post the Json?

Thanks

PaulOn Monday, 6 January 2014 14:59:43 UTC, Paul Sanders wrote:

Thanks Graeme,

That would explain why I was getting confused :slight_smile:

The Google document looks very interesting. Let me have a play with that
this evening and let you know how I get on :slight_smile:

On Monday, 6 January 2014 14:53:16 UTC, Graeme Boyd wrote:

Hi Paul,

The script you link was written in 2009 and I’m pretty sure Twitter was
only supporting OAuth 1.0 then. FreeAgent uses OAuth 2 so I’d think that
code is unlikely to work.

A quick google returns various python OAuth 2 libraries and Google has
their own library which is likely to work too:
GitHub - googleapis/google-api-python-client: 🐍 The official Python client library for Google's discovery based APIs.

Kind regards,

Graeme

On 6 January 2014 14:19, Paul Sanders paul.sa...@gmail.com wrote:

Hi All,

Does anyone know of a Python example on how I can complete the OAuth
process with the FreeAgent API?

I have been using the Django code snippet at
djangosnippets: Twitter oAuth example. However, I am getting ‘module’
object has no attribute ‘OAuthConsumer’ from Line 20.

Thanks in advance,

Paul


You received this message because you are subscribed to the Google
Groups “FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to freeagent_ap...@googlegroups.com.
To post to this group, send email to freeag...@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com http://www.freeagent.com/ Blog. The FreeAgent Blog - FreeAgent
Twitter. @freeagent https://twitter.com/#!/freeagent Facebook.
FreeAgent | Edinburgh

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774

Thanks Graeme,

That would explain why I was getting confused :slight_smile:

The Google document looks very interesting. Let me have a play with that
this evening and let you know how I get on :)On Monday, 6 January 2014 14:53:16 UTC, Graeme Boyd wrote:

Hi Paul,

The script you link was written in 2009 and I’m pretty sure Twitter was
only supporting OAuth 1.0 then. FreeAgent uses OAuth 2 so I’d think that
code is unlikely to work.

A quick google returns various python OAuth 2 libraries and Google has
their own library which is likely to work too:
GitHub - googleapis/google-api-python-client: 🐍 The official Python client library for Google's discovery based APIs.

Kind regards,

Graeme

On 6 January 2014 14:19, Paul Sanders <paul.sa...@gmail.com <javascript:>>wrote:

Hi All,

Does anyone know of a Python example on how I can complete the OAuth
process with the FreeAgent API?

I have been using the Django code snippet at
djangosnippets: Twitter oAuth example. However, I am getting ‘module’
object has no attribute ‘OAuthConsumer’ from Line 20.

Thanks in advance,

Paul


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_ap...@googlegroups.com <javascript:>.
To post to this group, send email to freeag...@googlegroups.com<javascript:>
.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com http://www.freeagent.com/ Blog. The FreeAgent Blog - FreeAgent
Twitter. @freeagent https://twitter.com/#!/freeagent Facebook.
FreeAgent | Edinburgh

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774

Hi Paul,

If you’re trying to build an app for other users to access their FreeAgent
accounts then FreeAgent’s OAuth 2.0 implementation is very similar to the
OAuth implementations for Facebook, GitHub and Google (and many, many
others) so I’d suggest looking for code samples for these services. I’m
not aware of any published implementations in Python specifically for
FreeAgent but the differences compared to other services using OAuth 2.0
will be minimal.

If you just want to use the FreeAgent API with your own account, it’s not
necessary to implement OAuth. Just use the Google OAuth 2.0 playground to
get an access and request token and you can use anything which makes http
requests to interact with the FreeAgent API. See
FreeAgent Developer Dashboard and
FreeAgent Developer Dashboard

Kind regards,

GraemeOn 10 January 2014 13:46, Paul Sanders paul.sanders87@gmail.com wrote:

Hi Graeme,

I have had a look at the link you sent and still haven’t the foggiest how
to utilise that information and make it work.

Do you know whether there is an example anywhere that will show me how to
do the OAuth request so I can post the Json?

Thanks

Paul

On Monday, 6 January 2014 14:59:43 UTC, Paul Sanders wrote:

Thanks Graeme,

That would explain why I was getting confused :slight_smile:

The Google document looks very interesting. Let me have a play with that
this evening and let you know how I get on :slight_smile:

On Monday, 6 January 2014 14:53:16 UTC, Graeme Boyd wrote:

Hi Paul,

The script you link was written in 2009 and I’m pretty sure Twitter was
only supporting OAuth 1.0 then. FreeAgent uses OAuth 2 so I’d think that
code is unlikely to work.

A quick google returns various python OAuth 2 libraries and Google has
their own library which is likely to work too: https://developers.
google.com/api-client-library/python/guide/aaa_oauth

Kind regards,

Graeme

On 6 January 2014 14:19, Paul Sanders paul.sa...@gmail.com wrote:

Hi All,

Does anyone know of a Python example on how I can complete the OAuth
process with the FreeAgent API?

I have been using the Django code snippet at
djangosnippets: Twitter oAuth example. However, I am getting ‘module’
object has no attribute ‘OAuthConsumer’ from Line 20.

Thanks in advance,

Paul


You received this message because you are subscribed to the Google
Groups “FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to freeagent_ap...@googlegroups.com.
To post to this group, send email to freeag...@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com http://www.freeagent.com/ Blog.
The FreeAgent Blog - FreeAgent
Twitter. @freeagent https://twitter.com/#!/freeagent Facebook.
FreeAgent | Edinburgh

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Graeme Boyd
Senior Software Engineer

Web. freeagent.com http://www.freeagent.com/ Blog. The FreeAgent Blog - FreeAgent
Twitter. @freeagent https://twitter.com/#!/freeagent Facebook.
FreeAgent | Edinburgh

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774

Hi Paul,

The script you link was written in 2009 and I’m pretty sure Twitter was
only supporting OAuth 1.0 then. FreeAgent uses OAuth 2 so I’d think that
code is unlikely to work.

A quick google returns various python OAuth 2 libraries and Google has
their own library which is likely to work too:

Kind regards,

GraemeOn 6 January 2014 14:19, Paul Sanders paul.sanders87@gmail.com wrote:

Hi All,

Does anyone know of a Python example on how I can complete the OAuth
process with the FreeAgent API?

I have been using the Django code snippet at
djangosnippets: Twitter oAuth example. However, I am getting ‘module’
object has no attribute ‘OAuthConsumer’ from Line 20.

Thanks in advance,

Paul


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Graeme Boyd
Senior Software Engineer

Web. freeagent.com http://www.freeagent.com/ Blog. The FreeAgent Blog - FreeAgent
Twitter. @freeagent https://twitter.com/#!/freeagent Facebook.
FreeAgent | Edinburgh

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774

I satisfied with above answers but here I share code which is helpful for me. You may be try the code given below:

author = ‘bdm4’

import requests, json
import subprocess
import sys

authorize_url = “https://api.byu.edu/authorize
token_url = “https://api.byu.edu/token

#callback url specified when the application was defined
callback_uri = “<>”

test_api_url = “<<the URL of the API you want to call, along with any parameters, goes here>>”

#client (application) credentials - located at apim.byu.edu
client_id = ‘<>’
client_secret = ‘<>’

#step A - simulate a request from a browser on the authorize_url - will return an authorization code after the user is

prompted for credentials.

authorization_redirect_url = authorize_url + ‘?response_type=code&client_id=’ + client_id + ‘&redirect_uri=’ + callback_uri + ‘&scope=openid’

print "go to the following url on the browser and enter the code from the returned url: "
print “— " + authorization_redirect_url + " —”
authorization_code = raw_input('code: ')

step I, J - turn the authorization code into a access token, etc

data = {‘grant_type’: ‘authorization_code’, ‘code’: authorization_code, ‘redirect_uri’: callback_uri}
print “requesting access token”
access_token_response = requests.post(token_url, data=data, verify=False, allow_redirects=False, auth=(client_id, client_secret))

print “response”
print access_token_response.headers
print 'body: ’ + access_token_response.text

we can now use the access_token as much as we want to access protected resources.

tokens = json.loads(access_token_response.text)
access_token = tokens[‘access_token’]
print "access token: " + access_token

api_call_headers = {‘Authorization’: 'Bearer ’ + access_token}
api_call_response = requests.get(test_api_url, headers=api_call_headers, verify=False

Understand the python from basic to advance I take help of given source:
https://www.cetpainfotech.com/technology/aws-training