I am working on an app in flask and want to include Facebook profile pictures for users. Since I have a user's Facebook ID, I have found an easy way to access photos through the Facebook graph, which gives the JSON data to this URL:
Here is JSON data Which should return to img_url: "data": {"height": 200, "ISILIATAT": incorrect, "url": "JPG_REE", "width": 200}} < P> specific image url For, I am using requests to get a dragon dictionary with the Unicode object.
r = requests.get (img_url) .json () Returns r ['data'] [ 'URL']. Encoded ('UTF-8')
All this works fine in Python interpreter and gives the string with the image URL. Let me run, however, I get a keyer for 'data' Any ideas about what's going wrong?
Ile "/vagrant/app/templates/user/profile.html", line 1, "base.html"%} file in the top-level template code {%}, "/vagrant/app/templates/base.html", line 38 , "/vagrant/app/templates/user/profile.html" in the top-level template code {% block content%} {% endblock%}, line 9, in the block "content" & lt; P & gt; & Lt; Img src = "{{current_user.picture (200, 200)}}" & gt; & Lt; / P & gt; & Lt; Br> File "/vagrant/app/models.py", line 52, ['data'] ['url'] in photo return Keyword: 'Data'
In code:r = requests.get (img_url) .json () `
I think the
r
The result type can be instr
, so you should translate it like this:import json r = requests.get (img_url) .json () r_dict = Json.loads (r) returns r_dict ['data'] ['url']. Encoded ('utf-8')
Try it out
No comments:
Post a Comment