gpt4 book ai didi

Python,Facebook 图形 API -- AttributeError : 'GraphAPI' object has no attribute 'search'

转载 作者:行者123 更新时间:2023-11-28 21:03:42 25 4
gpt4 key购买 nike

有人问过这个问题,但从未回答过。

import facebook
graph = facebook.GraphAPI(access_token="your token",version="2.7")

从 Facebook SDK python 页面,我得到了以下代码:

# 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')))

这是 link .

然而,它不起作用。我不明白为什么。错误显示为

---------------------------------------------------------------------------
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'

这是什么意思?为什么这个例子不起作用?我似乎无法找到有关 GraphAPI 类的结构细节的文档,但我假设搜索是其中的一部分。

最佳答案

这是因为包所有者自 2016 年以来未使用此 SDK 的官方版本进行更新。

https://pypi.python.org/pypi/facebook-sdk

所以您的最新版本是 2.0.0。

pip freeze | grep "facebook-sdk"
facebook-sdk==2.0.0

如果你想继续使用这个包,你需要遵循 installation instructions for the git repo反而。

virtualenv facebookenv
source facebookenv/bin/activate
pip install -e git+https://github.com/mobolic/facebook-sdk.git#egg=facebook-sdk

然后在Python中,应该可以正常使用

>>> 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': ...

关于Python,Facebook 图形 API -- AttributeError : 'GraphAPI' object has no attribute 'search' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46261083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com