Hello.

You need to register via facebook using the django-rest-framework . For this purpose, I use django-rest-auth and django-allauth . The documentation has the following instructions.

settings:

 INSTALLED_APPS = ( ..., 'rest_framework', 'rest_framework.authtoken', 'rest_auth' ..., 'django.contrib.sites', 'allauth', 'allauth.account', 'rest_auth.registration', ..., 'allauth.socialaccount', 'allauth.socialaccount.providers.facebook', 'allauth.socialaccount.providers.twitter', ) 

views:

 from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter from rest_auth.registration.views import SocialLoginView class FacebookLogin(SocialLoginView): adapter_class = FacebookOAuth2Adapter 

urls:

 urlpatterns += [ ..., url(r'^rest-auth/facebook/$', FacebookLogin.as_view(), name='fb_login') ] 

The result is the following picture:

enter image description here

When I registered the application on Facebook I received App ID and App Secret .

But where to get this Acces token and Code ?

When I see similar buttons in someone's applications, the acces_token is in the link of the button itself, but I do not understand where it is generated.

Can anybody explain the mechanism, how does this whole thing work?

    1 answer 1

    You need to send access _token and userID , which is returned in response the FB.login function:

     FB.login(function(response): console.log(response) accessToken = response['authResponse'].accessToken userID = response['authResponse'].userID 

    And then this data needs to be transferred to the server, for example:

     $.ajax({ url: "http://127.0.0.1:8000/rest-auth/facebook/", method: "post", data: { "access_token": accessToken, "code": userID } 

    and in response, the backend server returns a token that corresponds to this user.