Django: SocialApp matching query does not exist
Asked Answered
D

9

55

I'm using django-allauth, and I configured localhost:9000/admin/ with the following details:

socialapp .
provider:
Name:
Client id:
App ID, or consumer key
Key:
Secret:  etc .

I set SITE_ID = 2 (because I changed the default site example.com to localhost:9000)

In settings.py:

   INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'django.contrib.admin',
        'uni_form',
        'allauth',
        'allauth.account',
        'allauth.socialaccount',
        'bootstrapform',
        # 'allauth.socialaccount.providers.twitter',
        # 'allauth.socialaccount.providers.openid',
         'allauth.socialaccount.providers.facebook',
    )
    SOCIALACCOUNT_PROVIDERS = \
        { 'facebook':
            { 'SCOPE': ['email', 'publish_stream'],
              'AUTH_PARAMS': { 'auth_type': 'reauthenticate' },
              'METHOD': 'oauth2' ,
              'LOCALE_FUNC': 'path.to.callable'} }

When I go to:

http://localhost:9000/accounts/facebook/login

I get:

Error :  `SocialApp matching query does not exist.

What am I doing wrong?

Dimphia answered 14/3, 2013 at 12:30 Comment(0)
C
80

Using the Django admin you need to create a SocialApp listing your Facebook app credentials. Make sure that this app is attached to the proper site (as in, django.contrib.sites.models.Site).

In your case, there needs to be a django.contrib.sites.models.Site instance with id=2 (check the sites admin) that is listed as a site for the SocialApp.

If either the SocialApp is missing, or if it is created but not attached to a site matching your settings.SITE_ID, then allauth does not know what app to pick, resulting in the error message you listed above.

Chanukah answered 15/3, 2013 at 9:35 Comment(6)
thanks author i was missing django.contrib.sites.models.Site lineDimphia
I couldn't get the admin panel to show my SITE's id, so I loaded it in a shell: from django.contrib.sites.models import Site and did a Site.objects.all() to see the list. Site.objects.get(id=2) was actually set to example, so I had to change my settings to 3, which was what my localhost was set to.Om
I was getting this error in testing. This gave me a clue to the problem. In your set up you have to add from allauth.utils import get_current_site from allauth.socialaccount.models import SocialApp sa = SocialApp.objects.create(name='Facebook', provider='facebook') sa.sites.add(get_current_site())Meridional
Addendum to above. I also had to add my app's actual client_id and secret for testing the login of a Facebook test user.Meridional
@AdamStarrh, to see the site ID in the admin panel just add admin.site.unregister(Site) and then class SiteAdmin(admin.ModelAdmin): list_display = ('id', 'domain', 'name') and finally admin.site.register(Site, SiteAdmin) to your admin.py file.Obscurantism
I do this: user$ python manage.py shell. Then from within the interactive prompt, I issue the following two commands: >>> from django.contrib.sites.models import Site and then >>> sorted([(site.id,site.name) for site in Site.objects.all()]). The output looks like: [(1, u'www.lvh.me'), (2, u'example.com'), (3, u'www.example.com'), (4, u'example.com:80'), (5, u'www.example.com:80')]Cervicitis
H
19

For me, it showed this error when I had in settings.py:

SITE_ID = 1

It worked when I changed it to 2:

SITE_ID = 2
Harmonicon answered 4/11, 2019 at 15:18 Comment(1)
For me i changed it to 3 and it worked.Barfield
H
19

In my case, on the Add social application page, I forgot to select my site as "Chosen sites" 🤦🏼‍♂️

See screenshot below (on the bottom right is the Chosen Sites list): enter image description here

Haddad answered 12/3, 2020 at 9:38 Comment(1)
This worked after trying the other answers.Barfield
R
19

Step 1: Go to your admin page. Find social application

enter image description here

Step 2: now add the lines like the following image. Give your client id and secret key given by google api and move available site (example.com) to chosen sites enter image description here

Step 3: Now go to sites in the side navigation of admin page and customize like the following image and save it

enter image description here

Step 4: now, add, SITE_ID = 1 in settings.py file.

Registrar answered 25/10, 2020 at 13:26 Comment(0)
R
4

As an alternative to putting that into the admin, you can also put it in your settings like so: (At least in 2022 with version django-allauth==0.45.0

SOCIALACCOUNT_PROVIDERS = {
    'discord': {
        # From https://developer.twitter.com
        'APP': {
            'client_id': os.environ['TWITTER_API_KEY'],
            'secret': os.environ['TWITTER_API_SECRET'],
            'key': os.environ['TWITTER_APP_ID'],
        }
    },
    'twitter': {
        # From https://developer.twitter.com
        'APP': {
            'client_id': os.environ['TWITTER_API_KEY'],
            'secret': os.environ['TWITTER_API_SECRET'],
            'key': os.environ['TWITTER_APP_ID'],
        }
    },
}

Documentation is at: https://django-allauth.readthedocs.io/en/latest/installation.html and https://django-allauth.readthedocs.io/en/latest/configuration.html

Rolandorolandson answered 22/1, 2022 at 17:3 Comment(0)
A
1

It is possible that Django created an 'example.com' site for you already (if it's not a new project). So if this is the case you will need to delete that entry from the Sites admin page AND change the SITE_ID in settings.py to be the correct ID (probably 2 rather than 1).

Consider playing around with the SITE_ID value. For example: SITE_ID = 3, etc.

Auraaural answered 27/8, 2022 at 20:39 Comment(0)
A
1

FWIW, if configuration via the DB is giving you problems, note that you can also use configuration in settings:

SOCIALACCOUNT_PROVIDERS = {
"google": {
    "APP": {
        "client_id": os.environ[("GOOGLE_OAUTH_CLIENT_ID"],
        "secret": os.environ[("GOOGLE_OAUTH_SECRET"],
    },
},
}

@Penners

Auraaural answered 30/8, 2022 at 9:41 Comment(1)
You gave multiple answers to the same question. Edit your first answer to incorporate all information. Also note that some hints could be provided as comment.Gazelle
T
1

In my case
It worked me with SITE_ID = 4
SO what you need to do is keep on changing SITE_ID and keep stopping and restarting the server

Tarboosh answered 5/7, 2024 at 5:59 Comment(0)
M
0

This worked for me

    SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE' : [
            'profile',
            'email'
        ],
        'APP': {
            'client_id': os.environ['CLIENT_ID'],
            'secret': os.environ['CLIENT_SECRET'],
        },
        'AUTH_PARAMS': {
            'access_type':'online',
        }
    }
}
Mauney answered 18/8, 2023 at 22:16 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.