From 816a3c46025c0d460fe91af00589b052735df8c4 Mon Sep 17 00:00:00 2001 From: Viktor Fedoriv Date: Wed, 3 Jul 2024 18:48:03 +0300 Subject: [PATCH] fix: allow calls with channels along with api key authentication --- googlemaps/client.py | 6 +++--- tests/test_client.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/googlemaps/client.py b/googlemaps/client.py index d1f4ab6a..cfb06868 100644 --- a/googlemaps/client.py +++ b/googlemaps/client.py @@ -77,7 +77,6 @@ def __init__(self, key=None, client_id=None, client_secret=None, :param channel: (for Maps API for Work customers) When set, a channel parameter with this value will be added to the requests. This can be used for tracking purpose. - Can only be used with a Maps API client ID. :type channel: str :param timeout: Combined connect and read timeout for HTTP requests, in @@ -390,9 +389,10 @@ def _generate_auth_url(self, path, params, accepts_clientid): else: params = sorted(extra_params.items()) + params[:] # Take a copy. + if self.channel: + params.append(("channel", self.channel)) + if accepts_clientid and self.client_id and self.client_secret: - if self.channel: - params.append(("channel", self.channel)) params.append(("client", self.client_id)) path = "?".join([path, urlencode_params(params)]) diff --git a/tests/test_client.py b/tests/test_client.py index 4f01e397..7af066c7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -310,7 +310,7 @@ def test_auth_url_with_channel(self): auth_url = client._generate_auth_url( "/test", {"param": "param"}, accepts_clientid=False ) - self.assertEqual(auth_url, "/test?param=param&key=AIzaasdf") + self.assertEqual(auth_url, "/test?param=param&channel=MyChannel_1&key=AIzaasdf") def test_requests_version(self): client_args_timeout = {