Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

peterhudec commented Mar 20, 2015

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

This comment has been minimized.

Copy link
Owner Author

tejovanthn commented Mar 20, 2015

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
You can’t perform that action at this time.