如何使用mLewisLogic python包装器在Foursquare中搜索用户?

时间:2014-01-13 15:57:45

标签: python api foursquare

我在使用Foursquare API时遇到了一些麻烦。我的最终目标是从Foursquare API获取用户的信息(个人资料统计信息,Twitter ID,facebooks ID,...)。我想通过Twitter ID或名称搜索用户。我的第一次尝试是使用foursquare推荐的python包装器foursquare。以下是文档:https://github.com/mLewisLogic/foursquare

这是我非常简单的代码:

import foursquare

client_id = xxx
client_secret = yyy

client = foursquare.Foursquare(client_id, client_secret)

print client.users.search(params={'twitter': 'nike'})

这是我的错误:

 Traceback (most recent call last):
  File "D:\Users\nbush\workspace\Foursquare - API\main_foursq.py", line 12, in <module>
    users = client.users.search(params={'twitter': 'nike'})
  File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 301, in search
    return self.GET('search', params, multi=multi)
  File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 272, in GET
    return self.requester.GET(self._expanded_path(path), *args, **kwargs)
  File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 200, in GET
    result = _get(url, headers=headers, params=params)
  File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 787, in _get
    return _process_response(response)
  File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 822, in _process_response
    return _raise_error_from_response(data)
  File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 834, in 
  _raise_error_from_response
    raise exc(meta.get('errorDetail'))
foursquare.NotAuthorized: A user is required to call this endpoint.

任何帮助都会很棒。此外,如果有更好的API或更简单的方法与urllib2或其他东西,所以任何建议将不胜感激。 Alos,有没有人知道mLewisLogic是否与foursquare API v2保持同步?还有更完整的文档吗?提前谢谢!

1 个答案:

答案 0 :(得分:0)

添加access_token

client = foursquare.Foursquare(client_id, client_secret, **access_token**)