Skip to content

Instantly share code, notes, and snippets.

@psych0der
Created March 15, 2014 16:03
Show Gist options
  • Save psych0der/9569586 to your computer and use it in GitHub Desktop.
Save psych0der/9569586 to your computer and use it in GitHub Desktop.
python social auth social information QA
hi psych0der
psych0der
hey cadillac_
psych0der
i am bit cofused about accessing info about user object which is created in request
cadillac_
the social info?
psych0der
yes
psych0der
i noticed there is social_auth attribute inside user object
psych0der
which is in request
psych0der
but i did print dir(request.user.social_auth)
psych0der
then i didnt find anything usefil
psych0der
useful*
cadillac_
it's a selector because the relation is by foreignkey
psych0der
so how to use it
psych0der
?
cadillac_
you need to do this: request.social_auth.get(provider='facebook')
psych0der
ohk
cadillac_
(assuming facebook provider)
psych0der
in the code for usersocialauth there was foreign key to user model , was that bi directional foreign key?
psych0der
means how can we access social user model from auth user ?
cadillac_
django makes it bi-directional
cadillac_
check the doc for the field here https://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey
psych0der
ohk
psych0der
and if i want to access information about user which is not online , whats the best wa to do so ? how do get to know whats uid ?
psych0der
or should i search by email of name ?
cadillac_
but basically user.social_auth is a query selector, similar to User.objects, you can apply filters and other QS methods to it
cadillac_
psych0der, not online? like not logged in your site at the moment?
psych0der
i am sorry there was connection error
cadillac_
let me repeat my last two lines
cadillac_
but basically user.social_auth is a query selector, similar to User.objects, you can apply filters and other QS methods to it
cadillac_
psych0der, not online? like not logged in your site at the moment?
psych0der
yeah thanx for that :)
psych0der
so this means that i need to know some attribute like email for that ?
cadillac_
psych0der, I'm not sure I follow you
psych0der
ohk.
psych0der
one last question
psych0der
now i have my user logged in and i have access token
cadillac_
you need the info of a user that has signed up in your site at least once, right?
psych0der
how do i fetch other details from service provider like posts from facebook using graph.facebook.com
psych0der
?
cadillac_
psych0der, you need to call the API using that access token
psych0der
so is that access token accessible from social_auth user data ?
cadillac_
python-social-auth only cares about auth and basic info
cadillac_
so, once you identified the API you want to call, just do it using the access_token which you can retrieve by doing:
cadillac_
request.user.social_auth.get(provider='facebook').extra_data['access_token']
psych0der
got it :)
psych0der
would you mind if i ask just 1 more question ? :p
cadillac_
sure, np
psych0der
i am using django app example from the app
psych0der
but when i click the disconnect link after connecting
psych0der
django throws this in terminal : [15/Mar/2014 05:37:02] "GET /disconnect/google-oauth2/532411970638c712fe4d7753/ HTTP/1.1" 405 0
psych0der
but page doesnt show anything
cadillac_
disconnect must go by POST
psych0der
how do i ensure that
psych0der
?
cadillac_
with a form
psych0der
i am using this :
psych0der
{% for assoc in backends.associated %}
psych0der
<li>
psych0der
{{ assoc.provider }} (<a href="{% url 'social:disconnect_individual' assoc.provider assoc.id %}" class="disconnect">Disconnect</a> or <a href="/logout/">logout</a>)
psych0der
</li>
psych0der
{% endfor %}
cadillac_
<form action="/disconnect/facebook" method="post"><button>Disconnect</button></form>
cadillac_
the example app has a jQuery click handler on those disconnect links to ensure that it goes by POST
psych0der
oh i see.
cadillac_
maybe it's failing for some reason, an JS error in your console?
psych0der
how do i then determine how which service i need to disconnect dynamically ?
psych0der
i didnt get any
cadillac_
do you plan to use several services?
psych0der
yes
psych0der
I am making an recommendation engine of users
psych0der
based on data from several social networks
psych0der
i think i can make it post by some other method
psych0der
:)
cadillac_
you can build your disconnect UI with this simple snippet https://gist.github.com/omab/2d9dac4b153afb132129
psych0der
got it :)
psych0der
thanx a lot cadillac_ :)
psych0der
i think this channel should have irc logger
psych0der
lots of good advice is getting lost
cadillac_
yeah, I should setup that sometime
psych0der
:)
psych0der
thanx :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment