Fandjango Facebook用户只返回一些Facebook字段

我正在使用Fan
django并尝试访问Facebook用户的relationship_status和significant_other.name,但它无法找到这些属性.我的代码:

from django.shortcuts import render
from quiz.models import Quiz, Question
from django.http import HttpResponse
from fandjango.decorators import facebook_authorization_required

@facebook_authorization_required(permissions=['user_activities', 'user_hometown', 'user_interests', 'user_location', 'user_relationship_details', 'user_events', 'friends_relationships'])
def home(request):
    user = request.facebook.user
    print dir(user)


    context = {
    'user': user,           
    }

return render(request, 'quiz/home.html', context)

我已经打印出https://developers.facebook.com/docs/graph-api/reference/user/中所有Facebook属性的列表,以跟踪哪些有效,哪些无效:

<ul>
    <li>ID: {{user.id}}</li>
    <li>Link: {{user.link}}</li>
    <li>First Name: {{user.first_name}}</li>
    <li>Quotes: {{user.quotes}}</li>
    <li>Name: {{user.name}}</li>
    <li>Hometown: {{user.hometown}}</li>
    <li>Bio: {{user.bio}}</li>
    <li>Religion: {{user.religion}}</li>
    <li>Middle Name: {{user.middle_name}}</li>
    <li>About: {{user.about}}</li>
    <li>Verified: {{user.is_verified}}</li>
    <li>Gender: {{user.gender}}</li>
    <li>Third-party: {{user.third_party_id}}</li>
    <li>Relationship-status: {{user.relationship_status}}</li>
    <li>Last-name: {{user.last_name}}</li>
    <li>Locale: {{user.locale}}</li>
    <li>Verified: {{user.verified}}</li>
    <li>Political: {{user.political}}</li>
    <li>Name-format: {{user.name_format}}</li>
    <li>Sig Other: {{user.significant_other}}</li>
    <li>Website: {{user.website}}</li>
    <li>Location: {{user.location}}</li>
    <li>Username: {{user.username}}</li>
</ul>

这只会产生ID,中间名,性别,姓氏和区域设置.似乎很清楚我只获得了public profile属性,但是没有得到如何访问其余的属性.

为了弄清楚我有权访问哪些属性,我运行了dir(user)命令并产生:

['DoesNotExist', 'MultipleObjectsReturned', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', u'__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', '_base_manager', '_default_manager', '_deferred', '_do_insert', '_do_update', '_get_FIELD_display', '_get_next_or_previous_by_FIELD', '_get_next_or_previous_in_order', '_get_pk_val', '_get_unique_checks', '_meta', '_oauth_token_cache', '_perform_date_checks', '_perform_unique_checks', '_save_parents', '_save_table', '_set_pk_val', '_state', 'answer_set', 'authorized', 'birthday', 'clean', 'clean_fields', 'created_at', 'date_error_message', 'delete', 'email', 'extra_data', 'facebook_id', 'facebook_username', 'first_name', 'full_clean', 'full_name', 'gender', 'get_next_by_created_at', 'get_next_by_last_seen_at', 'get_previous_by_created_at', 'get_previous_by_last_seen_at', 'graph', 'id', 'last_name', 'last_seen_at', 'locale', 'middle_name', 'oauth_token', 'oauth_token_id', 'objects', 'permissions', 'picture', 'pk', 'prepare_database_save', 'save', 'save_base', 'serializable_value', 'synchronize', 'unique_error_message', 'validate_unique']

显然,这显示了正在工作的那些,并没有列出那些没有的.

我觉得我错过了一些非常明显的访问非公开个人资料属性的东西,但实际上我不知道它是什么.

编辑:
在做了更多的研究之后,我开始认为我需要将用户的auth_token传递给图形API来获取我想要的所有属性,但不知道如何在Fandjango框架中这样做.这是我的第一次尝试,但它返回“Graph API对象不可调用”:

oauth = request.facebook.user.oauth_token
user = request.facebook.user
facebook_graph = user.graph(oauth)

最佳答案 希望你不要把你的头发拉得太多了:).要获取不属于用户公共配置文件的任何属性,您需要调用:

user = request.facebook.user.graph.get('me')

用户对象现在将具有您有权使用@facebook_authorization_required(permissions = [< your_permissions_here>]装饰器)的属性.

点赞