2012-07-14 4 views
0

이것은 아마도 어리석은 질문 일 텐데, 너무 오랫동안 내 머리를 긁적 거리고있었습니다.Facepy를 사용하여 페이 스북 데이터 요청

페이스 북의 GraphAPI에서 django의 Facepy/social-auth를 사용하여 사진 정보를 요청하려고합니다.

내보기에는 다음 코드가 있지만 결과 json을 파이썬 개체로 변환하는 방법은 무엇입니까?

instance = UserSocialAuth.objects.filter(user=request.user).filter(provider='facebook') 
graph = GraphAPI(instance[0].extra_data['access_token']) 
p=graph.get('me/photos') 

Facepy 아주 좋은 것 같다,하지만 문서는 기껏해야, 사회 인증과 함께 좋은 재생 더 나은 파이썬 페이스 북 SDK가 좋지?

모든 제안에 감사드립니다. 당신은 simplejson의 부하를 사용할 수 있습니다

답변

0

from django.utils import simplejson 
simplejson.loads(args) 

를 작동 직렬화 s 파이썬 객체 (A JSON 문서를 포함하는 str 또는 unicode 예).

If ``s`` is a ``str`` instance and is encoded with an ASCII based encoding 
other than utf-8 (e.g. latin-1) then an appropriate ``encoding`` name 
must be specified. Encodings that are not ASCII based (such as UCS-2) 
are not allowed and should be decoded to ``unicode`` first. 

``object_hook`` is an optional function that will be called with the 
result of any object literal decode (a ``dict``). The return value of 
``object_hook`` will be used instead of the ``dict``. This feature 
can be used to implement custom decoders (e.g. JSON-RPC class hinting). 

``parse_float``, if specified, will be called with the string 
of every JSON float to be decoded. By default this is equivalent to 
float(num_str). This can be used to use another datatype or parser 
for JSON floats (e.g. decimal.Decimal). 

``parse_int``, if specified, will be called with the string 
of every JSON int to be decoded. By default this is equivalent to 
int(num_str). This can be used to use another datatype or parser 
for JSON integers (e.g. float). 

``parse_constant``, if specified, will be called with one of the 
following strings: -Infinity, Infinity, NaN, null, true, false. 
This can be used to raise an exception if invalid JSON numbers 
are encountered. 

To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` 
kwarg. 
2

Facepy는 기본 파이썬 객체가 아닌 JSON을 반환합니다.

response = graph.get('me/photos') 

for photo in response['data']: 
    print photo['source'] 
관련 문제