Reputation: 2234
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.
Upvotes: 2
Views: 2765
Reputation: 59
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
pip uninstall facebook-sdk
pip install facebook-sdk==2.0.0
Upvotes: 0
Reputation: 19995
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.
pip freeze | grep "facebook-sdk"
facebook-sdk==2.0.0
If you want to continue using this package you will need to follow the installation instructions for the git repo instead.
virtualenv facebookenv
source facebookenv/bin/activate
pip install -e git+https://github.com/mobolic/facebook-sdk.git#egg=facebook-sdk
Then in Python, you should be able to use it normally
>>> import facebook
>>> graph = facebook.GraphAPI(access_token="YOUR_TOKEN", version="2.10")
>>> graph.search(type='place', center='37.4845306,-122.1498183', fields='name,location')
{u'paging': {u'cursors': {u'after': u'MjQZD'}, u'next': u'https://graph.facebook.com/v2.10/search?access_token=YOUR_TOKEN&fields=name%2Clocation&type=place¢er=37.4845306%2C-122.1498183&limit=25&after=MjQZD'}, u'data': [{u'id': u'166793820034304', u'name': u'Facebook HQ', u'location': {u'city': u'Menlo Park', u'zip': u'94025', u'country': u'United States', u'longitude': -122.1501, u'state': u'CA', u'street': ...
Upvotes: 6