diff --git a/metrika/api.py b/metrika/api.py index 77db047..964cd61 100644 --- a/metrika/api.py +++ b/metrika/api.py @@ -50,7 +50,10 @@ def get_counters(access_token): try: result_json = requests.get('https://api-metrika.yandex.ru/management/v1/counters', params=params, - headers={'Accept': 'application/x-yametrika+json'}, + headers={ + 'Accept': 'application/x-yametrika+json', + 'Authorization': 'OAuth {}'.format(access_token) + }, timeout=5 ).json() @@ -78,8 +81,10 @@ def get_counter_name(id, access_token): :return: counter_name (JSON) """ url = 'https://api-metrika.yandex.ru/management/v1/counter/{}?oauth_token={}'.format(id, access_token) - # TODO: change requests to aiohttp - r = requests.get(url=url) + r = requests.get(url=url, headers={ + 'Accept': 'application/x-yametrika+json', + 'Authorization': 'OAuth {}'.format(access_token) + }) json = r.json() return "{} ({})".format(json['counter']['name'], json['counter']['site']) diff --git a/metrika/commands/statistics.py b/metrika/commands/statistics.py index d2d12b5..8c4c4c3 100644 --- a/metrika/commands/statistics.py +++ b/metrika/commands/statistics.py @@ -79,13 +79,17 @@ def get_stats(self, counter, token, date1): params = { 'id': counter, - 'oauth_token': token, 'metrics': 'ym:s:pageviews,ym:s:users', 'date1': date1, 'date2': 'today' } - statistic = requests.get(self.API_URL, params=params, timeout=5).json() + headers = { + 'Authorization': 'OAuth {}'.format(token), + 'Content-Type': 'application/x-yametrika+json' + } + + statistic = requests.get(self.API_URL, params=params, timeout=5, headers=headers).json() hits, users = statistic['totals'][0] return hits, users