This question has been asked, but never answered.
import facebook
graph = facebook.GraphAPI(access_token="your token",version="2.7")
From the Facebook SDK python page, I got the following code:
# Search for places near 1 Hacker Way in Menlo Park, California.
places = graph.search(type='place',
center='37.4845306,-122.1498183',
fields='name,location')
# Each given id maps to an object the contains the requested fields.
for place in places['data']:
print('%s %s' % (place['name'].encode(),place['location'].get('zip')))
Here’s the link.
It doesn’t work however. I don’t get why. The error reads
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-21-56959958831f> in <module>()
1 # Search for places near 1 Hacker Way in Menlo Park, California.
----> 2 places = graph.search(type='place',
3 center='37.4845306,-122.1498183',
4 fields='name,location')
5
AttributeError: 'GraphAPI' object has no attribute 'search'
What does this mean? Why would the example not work? I can’t seem to find documentation on the specifics of how the GraphAPI class is structured, but I assume search is part of this.
2
Answers
This is because the package owner hasn’t updated with an official release for this SDK since 2016.
https://pypi.python.org/pypi/facebook-sdk
So the latest version for you is 2.0.0.
If you want to continue using this package you will need to follow the installation instructions for the git repo instead.
Then in Python, you should be able to use it normally
I had the same issue with wall-post command and facebook-sdk 3+ didn’t work so
pip install facebook-sdk==2.0.0 fixed the issue