Skip to content

Commit

Permalink
🐛 Source YouTube Analytics: fix check_connection 403 error (airbyte…
Browse files Browse the repository at this point in the history
  • Loading branch information
bazarnov authored and jhammarstedt committed Oct 31, 2022
1 parent 0c5c669 commit a3f4375
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@
- sourceDefinitionId: afa734e4-3571-11ec-991a-1e0031268139
name: YouTube Analytics
dockerRepository: airbyte/source-youtube-analytics
dockerImageTag: 0.1.1
dockerImageTag: 0.1.2
documentationUrl: https://docs.airbyte.io/integrations/sources/youtube-analytics
icon: youtube.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11525,7 +11525,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-youtube-analytics:0.1.1"
- dockerImage: "airbyte/source-youtube-analytics:0.1.2"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/youtube-analytics"
connectionSpecification:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ COPY source_youtube_analytics ./source_youtube_analytics
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.version=0.1.2
LABEL io.airbyte.name=airbyte/source-youtube-analytics
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ class JobsResource(HttpStream):
name = None
primary_key = None
http_method = None
raise_on_http_errors = True
url_base = "https://youtubereporting.googleapis.com/v1/"
JOB_NAME = "Airbyte reporting job"

def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
return None

def should_retry(self, response: requests.Response) -> bool:
# if the connected Google account is not bounded with target Youtube account,
# we receive `401: UNAUTHENTICATED`
if response.status_code == 401:
setattr(self, "raise_on_http_errors", False)
return False
else:
return super().should_retry(response)

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
return [response.json()]

Expand Down Expand Up @@ -169,13 +179,14 @@ def get_authenticator(config):
def check_connection(self, logger, config) -> Tuple[bool, any]:
authenticator = self.get_authenticator(config)
jobs_resource = JobsResource(authenticator=authenticator)

try:
jobs_resource.list()
except Exception as e:
return False, str(e)

return True, None
result = jobs_resource.list()
if result:
return True, None
else:
return (
False,
"The Youtube account is not valid. Please make sure you're trying to use the active Youtube Account connected to your Google Account.",
)

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = self.get_authenticator(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_check_connection(requests_mock):
access_token = "token"
mock_oauth_call = requests_mock.post("https://oauth2.googleapis.com/token", json={"access_token": access_token, "expires_in": 0})

mock_jobs_call = requests_mock.get("https://youtubereporting.googleapis.com/v1/jobs", json={})
mock_jobs_call = requests_mock.get("https://youtubereporting.googleapis.com/v1/jobs", json={"jobs": [1, 2, 3]})

source = SourceYoutubeAnalytics()
logger_mock, config_mock = MagicMock(), MagicMock()
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/youtube-analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ Quota usage is not an issue because data is retrieved once and then filtered, so

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.1.2 | 2022-09-29 | [17399](https://github.com/airbytehq/airbyte/pull/17399) | Fixed `403` error while `check connection` |
| 0.1.1 | 2022-08-18 | [15744](https://github.com/airbytehq/airbyte/pull/15744) | Fix `channel_basic_a2` schema fields data type |
| 0.1.0 | 2021-11-01 | [7407](https://github.com/airbytehq/airbyte/pull/7407) | Initial Release |

0 comments on commit a3f4375

Please sign in to comment.