【发布时间】:2012-05-23 21:54:22
【问题描述】:
我正在尝试获取我网站中已登录用户的 Facebook 用户名。我的视图中有这段代码(在 Django 上):
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')
当我执行return HttpResponseRedirect(graph_url) 时,我可以看到 JSON 数据。但是,我无法使用
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'
【问题讨论】:
标签: django json facebook-graph-api django-views