Strava API文档提供了以下示例代码,我复制并输入了自己的访问令牌和俱乐部ID:
from __future__ import print_statement
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
# Configure OAuth2 access token for authorization: strava_oauth
swagger_client.configuration.access_token = 'MY_ACCESS_TOKEN'
# create an instance of the API class
api_instance = swagger_client.ClubsApi()
id = MY_CLUB_ID # Integer | The identifier of the club.
page = 56 # Integer | Page number. (optional)
perPage = 56 # Integer | Number of items per page. Defaults to 30. (optional) (default to 30)
try:
# List Club Activities
api_response = api_instance.getClubActivitiesById(id, page=page, perPage=perPage)
pprint(api_response)
except ApiException as e:
print("Exception when calling ClubsApi->getClubActivitiesById: %s\n" % e)
我试着跑我明白了
^{pr2}$我还可以看到,我的swagger_client
导入也会得到相同的结果。我没试过安装这些软件包,但都没用。我读到,对于__future__
,我应该使用python2.7,但我目前使用的是3.6。在
我如何解决这个问题?在
1)第一行包含排印错误
应该是的
^{pr2}$但是,由于您使用的是Python3,所以实际上并不需要这个导入—有关详细信息,请参见this Q&A。在
2)
swagger_client
可能是从Strava OpenAPI definition生成的Python客户机。看起来您需要使用Swagger Codegen手动生成它。有几种方法可以做到这一点:安装Swagger Codegen的command-line version,然后运行:
相关问题 更多 >
编程相关推荐