FacebookUserConverter函数get_and_store_likes()给出错误?

时间:2013-11-23 10:36:45

标签: python facebook django-facebook

我正在使用django-facebook开发Facebook Canvas应用程序。 当我使用FacebookUserConverter.get_and_store_like()时,它会给我这个错误:

  

[Errno 10061]因为目标机器无法建立连接   积极拒绝它

我的应用名称为fbData,fbData.models包含以下类:

from django.conf import settings
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django_facebook.models import FacebookModel, get_user_model
from django_facebook.utils import get_profile_model
import logging
logger = logging.getLogger(__name__)


try:
    from django.contrib.auth.models import AbstractUser, UserManager
    class CustomFacebookUser(AbstractUser, FacebookModel):
    '''
    The django 1.5 approach to adding the facebook related fields
    '''
    objects = UserManager()
    # add any customizations you like

    middle_name = models.CharField(max_length=255, blank=True, null=True)
    verified = models.BooleanField(default=False) 
    locale = models.CharField(max_length=255, blank=True, null=True)
    languages = models.CharField(max_length=255, blank=True, null=True)
    link = models.CharField(max_length=255, blank=True, null=True)
    age_range = models.CharField(max_length=255, blank=True, null=True)
except ImportError, e:
    logger.info('Couldnt setup FacebookUser, got error %s', e)
    pass


# Create your models here.
class UserProfile(FacebookModel):
    '''
Inherit the properties from django facebook
'''
    user = models.OneToOneField(settings.AUTH_USER_MODEL)



@receiver(post_save)
def create_profile(sender, instance, created, **kwargs):
"""Create a matching profile whenever a user object is created."""
    if sender == get_user_model():
        user = instance
        profile_model = get_profile_model()
        if profile_model == UserProfile and created:
            profile, new = UserProfile.objects.get_or_create(user=instance)

我的fbData.views是:

@facebook_required(canvas=True)
def home(request,graph):
    context = RequestContext(request)
    facebook_converter = FacebookUserConverter(graph)
    user_data = facebook_converter.facebook_registration_data(graph.get('me')['username'])


    user_data['access_token'] = graph.access_token
    try:

        fb_user = CustomFacebookUser.objects.get(facebook_id=user_data['facebook_id'])

        fb_user.access_token = user_data['access_token']
        fb_user.save()
        facebook_converter.get_and_store_likes(fb_user)       
    except CustomFacebookUser.DoesNotExist:
        custom_facebook_user = CustomFacebookUser(password = user_data['username'],username = user_data['username'],first_name = user_data['first_name'],last_name = user_data['last_name'],is_active = True, facebook_id = user_data['facebook_id'])
        custom_facebook_user.save()
        facebook_converter.get_and_store_likes(custom_facebook_user)

我的settings.py包含:

CUSTOM_USER_MODEL = bool(int(os.environ.get('CUSTOM_USER_MODEL', '1')))

if DJANGO != '1.5.1':
    CUSTOM_USER_MODEL = False

if CUSTOM_USER_MODEL:
    AUTH_USER_MODEL = 'django_facebook.FacebookCustomUser'
else:
    AUTH_USER_MODEL = 'auth.User'
    AUTH_PROFILE_MODULE = 'fbData.UserProfile'

FACEBOOK_CELERY_STORE = True
FACEBOOK_CELERY_TOKEN_EXTEND = True

0 个答案:

没有答案