Skip to content

Instantly share code, notes, and snippets.

@tejovanthn
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tejovanthn/f2eae0cee36f54d6fb56 to your computer and use it in GitHub Desktop.
Save tejovanthn/f2eae0cee36f54d6fb56 to your computer and use it in GitHub Desktop.
authomatic test
from authomatic import Authomatic
authomatic = Authomatic(app.config['AUTHOMATIC'], app.config['SECRET_KEY'], report_errors=False)
@user.route('/login/<provider_name>/', methods=['GET', 'POST'])
def login_social(provider_name):
"""
Login handler, must accept both GET and POST to be able to use OpenID.
From the example at http://peterhudec.github.io/authomatic/examples/flask-simple.html
"""
response = make_response()
result = authomatic.login(WerkzeugAdapter(request, response),
provider_name, session=session,
session_saver=lambda : \
app.save_session(session, response))
if result:
if result.user:
result.user.update()
g.user = result.user
# <my changes>
r = authomatic.access(g.user.credentials, url="https://graph.facebook.com/me/friends")
print r.data
# returns: {u'data': [], u'summary': {u'total_count': 1500}}
# I have 'scope': ['email', 'user_friends'], defined in the config.
# Am I using authomatic.access() wrong?
# </my changes>
return render_template('user/login_social.html', result=result)
return response
@peterhudec
Copy link

Everything seems to be OK in your code. The access call seems to be successful (check r.status), but my r.data looks like this (there's no summary key):

{
    u'data': [
        {u'id': u'###', u'name': u'User Name 1'},
        {u'id': u'###', u'name': u'User Name 2'},
        {u'id': u'###', u'name': u'User Name 3'},
        # ...
    ],
    u'paging': {
        u'next': u'https://graph.facebook.com/v1.0/(...)'
    }
}

BTW you can also call access like this:

r = result.provider.access("https://graph.facebook.com/me/friends")

Are you sure that you have friends on facebook? (just kidding 😄)

@tejovanthn
Copy link
Author

I get r.status as 200

It's the same with the result.provider.access().

The app permissions are the default ones right? The ones when you create, or do i need to add some other permissions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment