本文整理汇总了Python中api.API.call_api方法的典型用法代码示例。如果您正苦于以下问题:Python API.call_api方法的具体用法?Python API.call_api怎么用?Python API.call_api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api.API
的用法示例。
在下文中一共展示了API.call_api方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_audio_list
# 需要导入模块: from api import API [as 别名]
# 或者: from api.API import call_api [as 别名]
def get_audio_list(owner_id, count=6000):
api = API()
params = {
'method': 'audio.get',
'owner_id': owner_id,
'count': count,
}
return api.call_api(**params)['response']
示例2: get_likes_list
# 需要导入模块: from api import API [as 别名]
# 或者: from api.API import call_api [as 别名]
def get_likes_list(method='fave.getPosts', count=1000000):
api = API()
params = {
'method': method,
'offset': 0,
'count': count,
'extended': 0,
}
first_page = api.call_api(**params)['response']
count = first_page.pop(0)
print 'Количество лайков: {0}'.format(count)
print 'Начинаю сбор записей'
posts = first_page
offset = len(first_page)
count -= offset
while count > 1:
print 'Смещение: {0}, всего осталось: {1}'.format(offset, count)
params['offset'] = offset
page = api.call_api(**params)['response']
page.pop(0)
offset += len(page)
count -= len(page)
posts.extend(page)
return posts
示例3: remove_all_likes_from_fav
# 需要导入模块: from api import API [as 别名]
# 或者: from api.API import call_api [as 别名]
def remove_all_likes_from_fav(except_list=list(), start_tuple=tuple()):
api = API()
antigate = AG()
likes_list = list()
if len(sys.argv) >= 2:
with open(sys.argv[1], 'r') as f:
ll = f.read()
likes_list = json.loads(ll)
if len(sys.argv) == 4:
start_tuple = (sys.argv[2], sys.argv[3])
if likes_list:
result_list = []
for like in reversed(likes_list):
like_params = {'id': like[1], 'from_id': like[0], 'post_type': 'post', }
result_list.append(like_params)
else:
result_list = get_likes_list(method='fave.getPhotos')
result_list.extend(get_likes_list())
likes_list = result_list
print 'Все записи с лайками собраны'
print 'Начинаю удаление лайков'
likes_len = len(likes_list) + 1
params = {
'method': 'likes.delete',
'debug': 1,
}
start = 0 or start_tuple == tuple() and 1
for like in likes_list:
likes_len -= 1
poi = like.get('id', None) and 'id' or like.get('pid', None) and 'pid'
foi = like.get('from_id', None) and 'from_id' or like.get('owner_id', None) and 'owner_id'
pid = like[poi]
params['item_id'] = pid
if poi == 'pid':
params['type'] = 'photo'
else:
params['type'] = like['post_type']
if params['type'] == 'copy':
if params['debug'] == 1:
print 'post_type: {0}'.format(like['post_type'])
params['type'] = 'post'
params['owner_id'] = like[foi]
if start == 0 and start_tuple and start_tuple == (params['owner_id'], params['item_id']):
start = 1
if start and pid and pid not in except_list:
is_liked_params = params
is_liked_params['method'] = 'likes.isLiked'
is_liked = api.call_api(**params)['response']
d = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')
if is_liked == 0:
print '{0}\t{1}: лайк к записи с номером {2} отсутствует'.format(d, likes_len, like[poi])
print 'https://vk.com/wall{owner_id}_{item_id}'.format(**params)
time.sleep(3)
continue
print '{0}\t{1}: Удаляю лайк с записи с номером {2}'.format(d, likes_len, like[poi])
response = api.call_api(**params)
print response
while 'error' in response and response['error']['error_code'] == 14:
params['captcha_key'] = antigate.captcha_solve(response['error']['captcha_img'])
params['captcha_sid'] = response['error']['captcha_sid']
response = api.call_api(**params)
print response
if 'error' in response and response['error']['error_code'] == 14:
antigate.abuse()
del params['captcha_key']
del params['captcha_sid']
time.sleep(3)
else:
print 'Пропускаем {0}_{1}'.format(params['owner_id'], params['item_id'])
示例4: test_call_api_method_with_required_params
# 需要导入模块: from api import API [as 别名]
# 或者: from api.API import call_api [as 别名]
def test_call_api_method_with_required_params(self):
my_api = API('fake_key')
my_api.required_params = {'api_key': my_api.api_key}
my_api.call_api('example', foo='bar')
expected_call = '/example?api_key=fake_key&foo=bar'
api.urlopen.assert_called_with(expected_call)