2

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
  • Which user-contributed facebook python sdk are you working with? Can you pip freeze | grep facebook and share the package name and version? Commented Sep 17, 2017 at 8:22
  • I'm working with facebook-sdk, is that what u mean? Commented Sep 18, 2017 at 8:49

2 Answers 2

6

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&center=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': ...
Sign up to request clarification or add additional context in comments.

2 Comments

Just did this here, still get the same GraphAPI error
@DavidFindlay Without extra details, I'm not sure what to reply here. Version 2.0.0 fixes the AttributeError, for generic GraphAPI errors it probably means you don't have the correct call.
0

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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.