2012-05-16 7 views
0

내 사이트에 로그인 한 사용자의 facebook 사용자 이름을 얻으려고합니다. 내가 return HttpResponseRedirect(graph_url)을 수행 할 때 내가 JSON 데이터를 볼 수 있습니다Facebook에서 반환하는 JSON 데이터를 읽는 방법 access_token

code = request.GET.get('code') 
url = 'https://graph.facebook.com/oauth/access_token?client_id=%(id)s&redirect_uri=http://127.0.0.1:8000/skempi/home&client_secret=%(secret)s&code=%(code)s'%{'id':fb_id,'secret':fb_s,'code':code} 
response = urllib2.urlopen(url) 
html = response.read() 
dic = dict(urlparse.parse_qsl(html)) 
graph_url = 'https://graph.facebook.com/me?access_token='+dic.get('access_token') 

: 내가 (장고에) 내보기에이 코드가 있습니다. 그러나, 나는이 오류가

import simplejson 
d = simplejson.load(graph_url) 
context ={'user':d} 
return render_to_response('home.html', context, context_instance=RequestContext(request))  

사용하여 해당 데이터를 읽을 수 아니에요 :

'str' object has no attribute 'read' 

답변

3

당신은 simplejson이 그것을 해독하기 전에 실제로 JSON을 다운로드해야합니다.

response = urllib2.urlopen(graph_url) 
data = simplejson.load(response) 
+0

감사합니다. –

관련 문제