tschellenbach / Django-facebook

Facebook open graph api implementation using the Django web framework in python
http://www.mellowmorning.com/
Other
1.43k stars 544 forks source link

myCustomProfile.friends() returns empty array #397

Closed Spencatro closed 10 years ago

Spencatro commented 10 years ago

Calling some instance of a MyCustomProfile object's friends() method returns an empty array. Data is being received from facebook (raw_data contains real data in the database), and I believe I have the necessary permissions turned on (the permissions page when authorizing the app explicitly states "read your friend list"). I'm also getting this issue (the following is the same data posted there, I just placed it here for posterity): https://github.com/tschellenbach/Django-facebook/issues/386

Running on Django 1.5.4 and django-facebook 5.2.10:

Relevant portions of settings.py:

  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2',       'mysql', 'sqlite3' or 'oracle'.
          'NAME': '/opt/django/mydb.db',                      # Or path to database       file if using sqlite3.
          # The following settings are not used with sqlite3:
          'USER': '',
          'PASSWORD': '',
          'HOST': '',                      # Empty for localhost through domain       sockets or '127.0.0.1' for localhost through TCP.
          'PORT': '',                      # Set to empty string for default.
      }
  }

  #
  #..unimportant unedited settings.py contents
  #

  ## django_facebook
  FACEBOOK_APP_ID = 'my_facebook_app_id'
  FACEBOOK_APP_SECRET = 'my_facebook_app_secret'
  ##of course these contain my real app info

  LOGIN_REDIRECT_URL = '/games/'
  FACEBOOK_LOGIN_DEFAULT_REDIRECT = '/games/'

  #I assume this is where something is going wrong

  AUTH_PROFILE_MODULE = 'games.MyCustomProfile'
  TEMPLATE_CONTEXT_PROCESSORS = (
      'django.contrib.auth.context_processors.auth',
      'django.core.context_processors.debug',
      'django.core.context_processors.i18n',
      'django.core.context_processors.media',
      'django.core.context_processors.static',
      'django.core.context_processors.tz',
      'django.core.context_processors.request',
      'django.contrib.messages.context_processors.messages',
      'django_facebook.context_processors.facebook',
  )

  AUTHENTICATION_BACKENDS = (
      'django_facebook.auth_backends.FacebookBackend',
      'django.contrib.auth.backends.ModelBackend',
  )

games.models.py

  from django.db import models
  from django_facebook.models import FacebookProfileModel
  from django.contrib.auth.models import UserManager
  # Create your models here.

  class MyCustomProfile(FacebookProfileModel):
      user = models.OneToOneField('auth.user')
      objects = UserManager()

  from django.contrib.auth.models import User
  from django.db.models.signals import post_save

  #Make sure we create a MyCustomProfile when creating a User
  def create_facebook_profile(sender, instance, created, **kwargs):
      if created:
          MyCustomProfile.objects.create(user=instance)

  post_save.connect(create_facebook_profile, sender=User)      

A sample of what raw_data is storing in the database:

{"website": "Spencer-Hawkins.com", "last_name": "Hawkins", "locale": "en_US", "hometown": {"id": "154754277895542", "name": "Tamuning, Guam"}, "image": "https://graph.facebook.com/me/picture?access_token=CAADeM5AbHLYBADGZCz3u5FWCWZCZC1Qwh4s8ZAlVr5yElKejvd05mzVBqQJtdRiW1RKGFk19BFf7gUH7HroOESfFpUvhZBGPqZC0qcceqXcrYz766JzOlZB0gnZCAOhOTkbkQTZB2KNvuOVznbbbPaZBOsnyqq8iJepg22BSuPFa5fTNL98jJcUJct&type=large", "quotes": "\"If you can't laugh at yourself, life is going to seem a whole lot longer than you'd like.\"\n\n--Sam, Garden State", "timezone": -8, "education": [{"school": {"id": "108015725885605", "name": "Klein Oak High School"}, "type": "High School", "year": {"id": "201638419856163", "name": "2011"}}, {"school": {"id": "105709269462549", "name": "University of Texas at Dallas"}, "type": "College", "concentration": [{"id": "104076956295773", "name": "Computer Science"}], "year": {"id": "105576766163075", "name": "2015"}}], "id": "580422245", "first_name": "Spencer", "verified": true, "location": {"id": "108233179205482", "name": "Richardson, Texas"}, "image_thumb": "https://graph.facebook.com/me/picture?access_token=CAADeM5AbHLYBADGZCz3u5FWCWZCZC1Qwh4s8ZAlVr5yElKejvd05mzVBqQJtdRiW1RKGFk19BFf7gUH7HroOESfFpUvhZBGPqZC0qcceqXcrYz766JzOlZB0gnZCAOhOTkbkQTZB2KNvuOVznbbbPaZBOsnyqq8iJepg22BSuPFa5fTNL98jJcUJct", "email": "hawkins.spencer@gmail.com", "username": "shawkinsl", "bio": "Removed due to offensive copyright infringement", "birthday": "09/28/1992", "link": "https://www.facebook.com/shawkinsl", "name": "Spencer Hawkins", "gender": "male", "work": [{"position": {"id": "105549279479057", "name": "Technician"}, "description": "Assembling, Soldering, QC/Testing, Troubleshooting various interfacing Circuit Boards that are deployed on OEM oil rigs.", "location": {"id": "107925612568471", "name": "Plano, Texas"}, "start_date": "2011-10-01", "employer": {"id": "133670130018876", "name": "Precise Circuits"}}, {"description": "I don't know yet, but man am I excited!", "end_date": "2014-05-29", "employer": {"id": "18790602800", "name": "Tesla Motors"}, "location": {"id": "104022926303756", "name": "Palo Alto, California"}, "position": {"id": "656983747675334", "name": "Powertrain Validation and Test Engineering Intern"}, "start_date": "2014-01-06"}, {"position": {"id": "108703555821060", "name": "Intern"}, "start_date": "2013-06-19", "location": {"id": "105396882827337", "name": "Pasadena, California"}, "end_date": "2013-08-31", "employer": {"id": "8261258923", "name": "Jet Propulsion Laboratory (JPL)"}}, {"description": "http://www.google.com/search?client=safari&rls=en-us&q=define:barback&ie=UTF-8&oe=UTF-8", "end_date": "2011-06-01", "employer": {"id": "148354981878238", "name": "Santikos"}, "location": {"id": "107879769240188", "name": "Tomball, Texas"}, "position": {"id": "208170149275530", "name": "Bartender"}, "start_date": "2008-09-01"}, {"description": "clearing Fancy tables of Fancy plates that once held Fancy food but was eaten by Fancy clients.", "end_date": "2009-06-01", "employer": {"id": "1391646277732473", "name": "Lobster Shop Dash"}, "location": {"id": "108537252503370", "name": "Dash Point, Washington"}, "position": {"id": "110448272309606", "name": "Busser"}, "start_date": "2008-06-01"}], "updated_time": "2013-11-29T20:56:44+0000"}
tschellenbach commented 10 years ago

It seems to me that storing friends is not enabled in your settings. See the docs on settings: http://django-facebook.readthedocs.org/en/latest/django_facebook/settings.html

You can also query the friend data directly from Facebook. Something like graph = user.get_offline_graph() if graph: friends = graph.get('me/friends')

Also see https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends