[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-13 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r407724327
 
 

 ##
 File path: airflow/utils/db.py
 ##
 @@ -240,6 +240,23 @@ def create_default_connections(session=None):
 ),
 session
 )
+merge_conn(
+Connection(
+conn_id="facebook_default",
+conn_type="facebook_social",
+schema="""
+{
+"facebook_ads_client": {
+"account_id": "act_123456789",
+"app_id": "1234567890",
+"app_secret": "1f45tgh12345",
+"access_token": "ABcdEfghiJKlmnoxxyz"
+}
+}
+""",
 
 Review comment:
   Is there any better way to show the schema ?? Cus for GCP there is a 
tutorial on google's website. Integrating with airflow. Any thoughts?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-07 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r404639844
 
 

 ##
 File path: airflow/providers/facebook/ads/operators/ads.py
 ##
 @@ -0,0 +1,119 @@
+#
 
 Review comment:
   Cool, but the hook is consumed from google/FacebookAdsToGCS/hooks ??


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-07 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r404602700
 
 

 ##
 File path: airflow/providers/facebook/ads/operators/ads.py
 ##
 @@ -0,0 +1,119 @@
+#
 
 Review comment:
   Will fix it according to the AIP. But what if tomorrow one would want 
integration with AWS or other cloud plf?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-02 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r402747195
 
 

 ##
 File path: airflow/providers/facebook/ads/operators/ads.py
 ##
 @@ -0,0 +1,108 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ad Reporting to GCS operators.
+"""
+import json
+import tempfile
+from typing import Any, Dict, List, Optional
+
+from airflow.models import BaseOperator
+from airflow.providers.facebook.ads.hooks.ads import FacebookAdsReportingHook
+from airflow.providers.google.cloud.hooks.gcs import GCSHook
+from airflow.utils.decorators import apply_defaults
+
+
+class FacebookAdsReportToGcsOperator(BaseOperator):
+"""
+Fetches the results from the Facebook Ads API as desired in the params
+Converts and saves the data as a temporary JSON file
+Uploads the JSON to Google Cloud Storage
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+.. seealso::
+For more information on the Facebook Ads Python SDK, take a look at 
the docs:
+https://github.com/facebook/facebook-python-business-sdk
+
+:param bucket: The GCS bucket to upload to
+:type bucket: str
+:param obj: GCS path to save the object. Must be the full file path (ex. 
`path/to/file.txt`)
+:type obj: str
+:param gcp_conn_id: Airflow Google Cloud Platform connection ID
+:type gcp_conn_id: str
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+:param fields: List of fields that is obtained from Facebook. Found in 
AdsInsights.Field class.
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type fields: List[str]
+:param params: Parameters that determine the query for Facebook
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type params: Dict[str, Any]
+:param gzip: Option to compress local file or file data for upload
+:type gzip: bool
+"""
+
+template_fields = ("facebook_ads_conn_id", "bucket_name", "object_name")
+
+@apply_defaults
+def __init__(
+self,
+bucket_name: str,
+object_name: str,
+gcp_conn_id: str = "google_cloud_default",
+facebook_ads_conn_id: str = "facebook_default",
+api_version: str = "v6.0",
+fields: Optional[List[str]] = None,
+params: Optional[Dict[str, Any]] = None,
+gzip: bool = False,
+*args,
+**kwargs,
+) -> None:
+super().__init__(*args, **kwargs)
+self.bucket_name = bucket_name
+self.object_name = object_name
+self.gcp_conn_id = gcp_conn_id
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.api_version = api_version
+self.fields = fields
+self.params = params  # type:ignore
+self.gzip = gzip
+
+def execute(self, context: Dict):
+service = 
FacebookAdsReportingHook(facebook_ads_conn_id=self.facebook_ads_conn_id,
+   api_version=self.api_version)
+rows = service.bulk_facebook_report(params=self.params, 
fields=self.fields)
+
+converted_rows = [dict(row) for row in rows]
 
 Review comment:
   yep cool, we can pass it as a arg! let the user decide.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-02 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r402746919
 
 

 ##
 File path: airflow/providers/facebook/ads/hooks/ads.py
 ##
 @@ -0,0 +1,152 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ads Reporting hooks
+"""
+import time
+from typing import Any, Dict, List, Optional
+
+from cached_property import cached_property
+from facebook_business.adobjects.adaccount import AdAccount
+from facebook_business.adobjects.adreportrun import AdReportRun
+from facebook_business.adobjects.adsinsights import AdsInsights
+from facebook_business.api import Cursor, FacebookAdsApi
+from facebook_business.exceptions import FacebookError, FacebookRequestError
+
+from airflow.exceptions import AirflowException
+from airflow.hooks.base_hook import BaseHook
+
+JOB_COMPLETED = "Job Completed"
+JOB_FAILED = "Job Failed"
+JOB_SKIPPED = "Job Skipped"
+
+
+class FacebookAdsReportingHook(BaseHook):
+"""
+Hook for the Facebook Ads API
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+
+"""
+
+def __init__(
+self,
+facebook_ads_conn_id: str = "facebook_default",
+api_version: str = "v6.0",
+) -> None:
+super().__init__()
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.api_version = api_version
+self.default_params = {
 
 Review comment:
   Yes, what would you suggest? Not to have default params and throw error if 
user does not enter data. I can make it a required field.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-02 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r402746519
 
 

 ##
 File path: airflow/providers/facebook/ads/hooks/ads.py
 ##
 @@ -0,0 +1,152 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ads Reporting hooks
+"""
+import time
+from typing import Any, Dict, List, Optional
+
+from cached_property import cached_property
+from facebook_business.adobjects.adaccount import AdAccount
+from facebook_business.adobjects.adreportrun import AdReportRun
+from facebook_business.adobjects.adsinsights import AdsInsights
+from facebook_business.api import Cursor, FacebookAdsApi
+from facebook_business.exceptions import FacebookError, FacebookRequestError
+
+from airflow.exceptions import AirflowException
+from airflow.hooks.base_hook import BaseHook
+
+JOB_COMPLETED = "Job Completed"
+JOB_FAILED = "Job Failed"
+JOB_SKIPPED = "Job Skipped"
+
+
+class FacebookAdsReportingHook(BaseHook):
+"""
+Hook for the Facebook Ads API
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+
+"""
+
+def __init__(
+self,
+facebook_ads_conn_id: str = "facebook_default",
+api_version: str = "v6.0",
+) -> None:
+super().__init__()
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.api_version = api_version
+self.default_params = {
+'level': 'ad',
+'date_preset': 'yesterday',
+}
+
+def _get_service(self) -> FacebookAdsApi:
+""" Returns Facebook Ads Client using a service account"""
+config = self.facebook_ads_config
+try:
+return FacebookAdsApi.init(app_id=config["app_id"],
+   app_secret=config["app_secret"],
+   access_token=config["access_token"],
+   account_id=config["account_id"],
+   api_version=self.api_version)
+except AirflowException as error:
+message = "Missing config data:\n {error}".format(error=error)
+self._error_handler(message)
+raise
+
+@cached_property
+def facebook_ads_config(self) -> None:
+"""
+Gets Facebook ads connection from meta db and sets
+facebook_ads_config attribute with returned config file
+"""
+conn = self.get_connection(self.facebook_ads_conn_id)
+if "facebook_ads_client" not in conn.extra_dejson:
+raise AirflowException("facebook_ads_client not found in extra 
field")
+return conn.extra_dejson.get("facebook_ads_client")
+
+def bulk_facebook_report(
+self,
+params: Optional[Dict[str, Any]] = None,
+fields: Optional[List[str]] = None,
+) -> List[AdsInsights]:
+"""
+Pulls data from the Facebook Ads API
+
+:param fields: List of fields that is obtained from Facebook. Found in 
AdsInsights.Field class.
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type fields: List[str]
+:param params: Parameters that determine the query for Facebook
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+
+:return: Facebook Ads API response, converted to Facebook Ads Row 
objects
+:rtype: List[AdsInsights]
+"""
+api = self._get_service()
+params = params if params else self.default_params
+ad_account = AdAccount(api.get_default_account_id(), api=api)
+_async = ad_account.get_insights(params=params, fields=fields, 
is_async=True)
+try:
+while _async.api_get()["async_status"] != JOB_COMPLETED:
+percent = _async.api_get()["async_percent_completion"]
+

[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-02 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r402731431
 
 

 ##
 File path: airflow/providers/facebook/ads/example_dags/example_ads.py
 ##
 @@ -0,0 +1,69 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+Example Airflow DAG that shows how to use FacebookAdsReportToGcsOperator.
+"""
+import os
+
+from facebook_business.adobjects.adsinsights import AdsInsights
+
+from airflow import models
+from airflow.providers.facebook.ads.operators.ads import 
FacebookAdsReportToGcsOperator
+from airflow.utils.dates import days_ago
+
+# [START howto_GCS_BUCKET_env_variables]
+GCS_BUCKET = os.environ.get("FACEBOOK_ADS_BUCKET", "airflow_bucket_fb")
+GCS_OBJ_PATH = "Temp/this_is_my_report_json.json"
+GCS_CONN_ID = "google_cloud_default"
+# [END howto_GCS_BUCKET_env_variables]
+
+# [START howto_FB_ADS_env_variables]
+FACEBOOK_ADS_CONN_ID = os.environ.get("FACEBOOK_ADS_CONN_ID", 
"facebook_ads_default")
+FIELDS = [
+AdsInsights.Field.campaign_name,
+AdsInsights.Field.campaign_id,
+AdsInsights.Field.ad_id,
+AdsInsights.Field.clicks,
+AdsInsights.Field.impressions,
+]
+PARAMS = {
+'level': 'ad',
+'date_preset': 'yesterday'
+}
+# [END howto_FB_ADS_env_variables]
+
+default_args = {"start_date": days_ago(1)}
+
+with models.DAG(
+"example_fb_operator",
+default_args=default_args,
+schedule_interval=None,  # Override to match your needs
+) as dag:
+# [START howto_FB_ADS_to_gcs_operator]
+run_operator = FacebookAdsReportToGcsOperator(
+task_id='run_fetch_data',
+start_date=days_ago(2),
+owner='airflow',
+facebook_ads_conn_id=FACEBOOK_ADS_CONN_ID,
+bucket_name=GCS_BUCKET,
+params=PARAMS,
+fields=FIELDS,
+gcp_conn_id=GCS_CONN_ID,
+object_name=GCS_OBJ_PATH,
+)
 
 Review comment:
   Sounds good! Will have a look @mik-laj 


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-01 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r401837518
 
 

 ##
 File path: airflow/providers/facebook/ads/operators/ads.py
 ##
 @@ -0,0 +1,111 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ad Reporting to GCS operators.
+"""
+import json
+import tempfile
+from typing import Any, Dict, List, Optional
+
+from airflow.models import BaseOperator
+from airflow.providers.facebook.ads.hooks.ads import FacebookAdsReportingHook
+from airflow.providers.google.cloud.hooks.gcs import GCSHook
+from airflow.utils.decorators import apply_defaults
+
+
+class FacebookAdsReportToGcsOperator(BaseOperator):
+"""
+Fetches the results from the Facebook Ads API as desired in the params
+Converts and saves the data as a temporary JSON file
+Uploads the JSON to Google Cloud Storage
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+.. seealso::
+For more information on the Facebook Ads Python SDK, take a look at 
the docs:
+https://github.com/facebook/facebook-python-business-sdk
+
+:param bucket: The GCS bucket to upload to
+:type bucket: str
+:param obj: GCS path to save the object. Must be the full file path (ex. 
`path/to/file.txt`)
+:type obj: str
+:param gcp_conn_id: Airflow Google Cloud Platform connection ID
+:type gcp_conn_id: str
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+:param fields: List of fields that is obtained from Facebook. Found in 
AdsInsights.Field class.
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type fields: List[str]
+:param params: Parameters that determine the query for Facebook
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type params: Dict[str, Any]
+:param gzip: Option to compress local file or file data for upload
+:type gzip: bool
+"""
+
+template_fields = ("facebook_ads_conn_id", "bucket", "obj")
+
+@apply_defaults
+def __init__(
+self,
+bucket: str,
+obj: str,
+gcp_conn_id: str = "google_cloud_default",
+facebook_ads_conn_id: str = "facebook_ads_default",
+api_version: str = "v6.0",
+fields: Optional[List[str]] = None,
+params: Optional[Dict[str, Any]] = None,
+gzip: bool = False,
+*args,
+**kwargs,
+) -> None:
+super().__init__(*args, **kwargs)
+self.bucket = bucket
+self.obj = obj
+self.gcp_conn_id = gcp_conn_id
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.api_version = api_version
+self.fields = fields
+self.params = params  # type:ignore
+self.gzip = gzip
+
+def execute(self, context: Dict):
+service = 
FacebookAdsReportingHook(facebook_ads_conn_id=self.facebook_ads_conn_id,
+   api_version=self.api_version)
+rows = service.bulk_facebook_report(params=self.params, 
fields=self.fields)
+try:
+converted_rows = [dict(row) for row in rows]
+except Exception as e:
+self.log.error("An error occurred in converting the Facebook Ad 
Rows. \n Error %s", e)
+raise
 
 Review comment:
   @turbaszek looks like I handling errors in the hook, thanks for pointing it 
out. I don't think the exception is required. Before I would iterate over the 
cursor in the operator, but now its just type casting.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-01 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r401837412
 
 

 ##
 File path: airflow/providers/facebook/ads/operators/ads.py
 ##
 @@ -0,0 +1,111 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ad Reporting to GCS operators.
+"""
+import json
+import tempfile
+from typing import Any, Dict, List, Optional
+
+from airflow.models import BaseOperator
+from airflow.providers.facebook.ads.hooks.ads import FacebookAdsReportingHook
+from airflow.providers.google.cloud.hooks.gcs import GCSHook
+from airflow.utils.decorators import apply_defaults
+
+
+class FacebookAdsReportToGcsOperator(BaseOperator):
+"""
+Fetches the results from the Facebook Ads API as desired in the params
+Converts and saves the data as a temporary JSON file
+Uploads the JSON to Google Cloud Storage
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+.. seealso::
+For more information on the Facebook Ads Python SDK, take a look at 
the docs:
+https://github.com/facebook/facebook-python-business-sdk
+
+:param bucket: The GCS bucket to upload to
+:type bucket: str
+:param obj: GCS path to save the object. Must be the full file path (ex. 
`path/to/file.txt`)
+:type obj: str
+:param gcp_conn_id: Airflow Google Cloud Platform connection ID
+:type gcp_conn_id: str
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+:param fields: List of fields that is obtained from Facebook. Found in 
AdsInsights.Field class.
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type fields: List[str]
+:param params: Parameters that determine the query for Facebook
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type params: Dict[str, Any]
+:param gzip: Option to compress local file or file data for upload
+:type gzip: bool
+"""
+
+template_fields = ("facebook_ads_conn_id", "bucket", "obj")
+
+@apply_defaults
+def __init__(
+self,
+bucket: str,
+obj: str,
+gcp_conn_id: str = "google_cloud_default",
+facebook_ads_conn_id: str = "facebook_ads_default",
+api_version: str = "v6.0",
+fields: Optional[List[str]] = None,
+params: Optional[Dict[str, Any]] = None,
+gzip: bool = False,
+*args,
+**kwargs,
+) -> None:
+super().__init__(*args, **kwargs)
+self.bucket = bucket
+self.obj = obj
+self.gcp_conn_id = gcp_conn_id
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.api_version = api_version
+self.fields = fields
+self.params = params  # type:ignore
+self.gzip = gzip
+
+def execute(self, context: Dict):
+service = 
FacebookAdsReportingHook(facebook_ads_conn_id=self.facebook_ads_conn_id,
+   api_version=self.api_version)
+rows = service.bulk_facebook_report(params=self.params, 
fields=self.fields)
+try:
+converted_rows = [dict(row) for row in rows]
+except Exception as e:
+self.log.error("An error occurred in converting the Facebook Ad 
Rows. \n Error %s", e)
+raise
 
 Review comment:
   @turbaszek looks like I handling errors in the hook, thanks for pointing it 
out. I don't think the exception is required. Before I would iterate over the 
cursor in the operator, but now its just type casting.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-01 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r401837518
 
 

 ##
 File path: airflow/providers/facebook/ads/operators/ads.py
 ##
 @@ -0,0 +1,111 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ad Reporting to GCS operators.
+"""
+import json
+import tempfile
+from typing import Any, Dict, List, Optional
+
+from airflow.models import BaseOperator
+from airflow.providers.facebook.ads.hooks.ads import FacebookAdsReportingHook
+from airflow.providers.google.cloud.hooks.gcs import GCSHook
+from airflow.utils.decorators import apply_defaults
+
+
+class FacebookAdsReportToGcsOperator(BaseOperator):
+"""
+Fetches the results from the Facebook Ads API as desired in the params
+Converts and saves the data as a temporary JSON file
+Uploads the JSON to Google Cloud Storage
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+.. seealso::
+For more information on the Facebook Ads Python SDK, take a look at 
the docs:
+https://github.com/facebook/facebook-python-business-sdk
+
+:param bucket: The GCS bucket to upload to
+:type bucket: str
+:param obj: GCS path to save the object. Must be the full file path (ex. 
`path/to/file.txt`)
+:type obj: str
+:param gcp_conn_id: Airflow Google Cloud Platform connection ID
+:type gcp_conn_id: str
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+:param fields: List of fields that is obtained from Facebook. Found in 
AdsInsights.Field class.
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type fields: List[str]
+:param params: Parameters that determine the query for Facebook
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type params: Dict[str, Any]
+:param gzip: Option to compress local file or file data for upload
+:type gzip: bool
+"""
+
+template_fields = ("facebook_ads_conn_id", "bucket", "obj")
+
+@apply_defaults
+def __init__(
+self,
+bucket: str,
+obj: str,
+gcp_conn_id: str = "google_cloud_default",
+facebook_ads_conn_id: str = "facebook_ads_default",
+api_version: str = "v6.0",
+fields: Optional[List[str]] = None,
+params: Optional[Dict[str, Any]] = None,
+gzip: bool = False,
+*args,
+**kwargs,
+) -> None:
+super().__init__(*args, **kwargs)
+self.bucket = bucket
+self.obj = obj
+self.gcp_conn_id = gcp_conn_id
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.api_version = api_version
+self.fields = fields
+self.params = params  # type:ignore
+self.gzip = gzip
+
+def execute(self, context: Dict):
+service = 
FacebookAdsReportingHook(facebook_ads_conn_id=self.facebook_ads_conn_id,
+   api_version=self.api_version)
+rows = service.bulk_facebook_report(params=self.params, 
fields=self.fields)
+try:
+converted_rows = [dict(row) for row in rows]
+except Exception as e:
+self.log.error("An error occurred in converting the Facebook Ad 
Rows. \n Error %s", e)
+raise
 
 Review comment:
   @turbaszek looks like I handling errors in the hook, thanks for pointing it 
out. I don't think the exception is required. Before I would iterate over the 
cursor in the operator, but now its just type casting.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-01 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r401831272
 
 

 ##
 File path: airflow/providers/facebook/ads/operators/ads.py
 ##
 @@ -0,0 +1,111 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ad Reporting to GCS operators.
+"""
+import json
+import tempfile
+from typing import Any, Dict, List, Optional
+
+from airflow.models import BaseOperator
+from airflow.providers.facebook.ads.hooks.ads import FacebookAdsReportingHook
+from airflow.providers.google.cloud.hooks.gcs import GCSHook
+from airflow.utils.decorators import apply_defaults
+
+
+class FacebookAdsReportToGcsOperator(BaseOperator):
+"""
+Fetches the results from the Facebook Ads API as desired in the params
+Converts and saves the data as a temporary JSON file
+Uploads the JSON to Google Cloud Storage
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+.. seealso::
+For more information on the Facebook Ads Python SDK, take a look at 
the docs:
+https://github.com/facebook/facebook-python-business-sdk
+
+:param bucket: The GCS bucket to upload to
+:type bucket: str
+:param obj: GCS path to save the object. Must be the full file path (ex. 
`path/to/file.txt`)
+:type obj: str
+:param gcp_conn_id: Airflow Google Cloud Platform connection ID
+:type gcp_conn_id: str
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+:param fields: List of fields that is obtained from Facebook. Found in 
AdsInsights.Field class.
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type fields: List[str]
+:param params: Parameters that determine the query for Facebook
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type params: Dict[str, Any]
+:param gzip: Option to compress local file or file data for upload
+:type gzip: bool
+"""
+
+template_fields = ("facebook_ads_conn_id", "bucket", "obj")
+
+@apply_defaults
+def __init__(
+self,
+bucket: str,
+obj: str,
+gcp_conn_id: str = "google_cloud_default",
+facebook_ads_conn_id: str = "facebook_ads_default",
+api_version: str = "v6.0",
+fields: Optional[List[str]] = None,
+params: Optional[Dict[str, Any]] = None,
+gzip: bool = False,
+*args,
+**kwargs,
+) -> None:
+super().__init__(*args, **kwargs)
+self.bucket = bucket
+self.obj = obj
+self.gcp_conn_id = gcp_conn_id
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.api_version = api_version
+self.fields = fields
+self.params = params  # type:ignore
+self.gzip = gzip
+
+def execute(self, context: Dict):
+service = 
FacebookAdsReportingHook(facebook_ads_conn_id=self.facebook_ads_conn_id,
+   api_version=self.api_version)
+rows = service.bulk_facebook_report(params=self.params, 
fields=self.fields)
+try:
+converted_rows = [dict(row) for row in rows]
+except Exception as e:
+self.log.error("An error occurred in converting the Facebook Ad 
Rows. \n Error %s", e)
+raise
+
+with tempfile.NamedTemporaryFile("w", suffix=".json") as json_file:
+json.dump(converted_rows, json_file)
+json_file.flush()
+hook = GCSHook(gcp_conn_id=self.gcp_conn_id)
+hook.upload(
+bucket_name=self.bucket,
+object_name=self.obj,
+filename=json_file.name,
+gzip=self.gzip,
+)
+self.log.info("%s uploaded to GCS", json_file.name)
 
 Review comment:
   @turbaszek Looks like the gsc hook accepts either filename->"Path to that 
file" or it excepts data.


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-01 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r401824549
 
 

 ##
 File path: airflow/providers/facebook/ads/hooks/ads.py
 ##
 @@ -0,0 +1,150 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ads Reporting hooks
+"""
+import time
+from typing import Any, Dict, List, Optional
+
+from facebook_business.adobjects.adaccount import AdAccount
+from facebook_business.adobjects.adreportrun import AdReportRun
+from facebook_business.adobjects.adsinsights import AdsInsights
+from facebook_business.api import Cursor, FacebookAdsApi
+from facebook_business.exceptions import FacebookRequestError
+
+from airflow.exceptions import AirflowException
+from airflow.hooks.base_hook import BaseHook
+
+JOB_COMPLETED = 'Job Completed'
+
+
+class FacebookAdsReportingHook(BaseHook):
+"""
+Hook for the Facebook Ads API
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+
+:return: list of Facebook Ads AdsInsights object(s)
+:rtype: list[AdsInsights]
+"""
+
+def __init__(
+self,
+facebook_ads_conn_id: str = "facebook_ads_default",
+api_version: str = "v6.0",
+) -> None:
+super().__init__()
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.facebook_ads_config: Dict[str, Any] = {}
+self.api_version = api_version
+self.ad_account_id: str = ""
+self.app_id: str = ""
+self.app_secret: str = ""
+self.access_token: str = ""
+self.default_params = {
+'level': 'ad',
+'date_preset': 'yesterday',
+}
+
+def _get_service(self) -> FacebookAdsApi:
+""" Returns Facebook Ads Client using a service account"""
+self._get_config()
+for key, val in self.facebook_ads_config.items():
+setattr(self, key, val)
+
+return FacebookAdsApi.init(app_id=self.app_id,
+   app_secret=self.app_secret,
+   access_token=self.access_token,
+   api_version=self.api_version)
+
+def _get_config(self) -> None:
+"""
+Gets Facebook ads connection from meta db and sets
+facebook_ads_config attribute with returned config file
+"""
+conn = self.get_connection(self.facebook_ads_conn_id)
+if "facebook_ads_client" not in conn.extra_dejson:
+raise AirflowException("facebook_ads_client not found in extra 
field")
+
+self.facebook_ads_config = conn.extra_dejson["facebook_ads_client"]
+
+def bulk_facebook_report(
+self,
+params: Optional[Dict[str, Any]] = None,
+fields: Optional[List[str]] = None,
+) -> List[AdsInsights]:
+"""
+Pulls data from the Facebook Ads API
+
+:param fields: List of fields that is obtained from Facebook. Found in 
AdsInsights.Field class.
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+:type fields: List[str]
+:param params: Parameters that determine the query for Facebook
+
https://developers.facebook.com/docs/marketing-api/insights/parameters/v6.0
+
+:return: Facebook Ads API response, converted to Facebook Ads Row 
objects
+:rtype: List[AdsInsights]
+"""
+api = self._get_service()
+params = params if params else self.default_params
+ad_account = AdAccount(self.ad_account_id, api=api)
+_async = ad_account.get_insights(params=params, fields=fields, 
is_async=True)
+try:
+while _async.api_get()["async_status"] != JOB_COMPLETED:
 
 Review comment:
   Yep, have solved will, re commit


This is an automated message from the 

[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-04-01 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r401824302
 
 

 ##
 File path: airflow/providers/facebook/ads/hooks/ads.py
 ##
 @@ -0,0 +1,150 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ads Reporting hooks
+"""
+import time
+from typing import Any, Dict, List, Optional
+
+from facebook_business.adobjects.adaccount import AdAccount
+from facebook_business.adobjects.adreportrun import AdReportRun
+from facebook_business.adobjects.adsinsights import AdsInsights
+from facebook_business.api import Cursor, FacebookAdsApi
+from facebook_business.exceptions import FacebookRequestError
+
+from airflow.exceptions import AirflowException
+from airflow.hooks.base_hook import BaseHook
+
+JOB_COMPLETED = 'Job Completed'
+
+
+class FacebookAdsReportingHook(BaseHook):
+"""
+Hook for the Facebook Ads API
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+
+:return: list of Facebook Ads AdsInsights object(s)
+:rtype: list[AdsInsights]
+"""
+
+def __init__(
+self,
+facebook_ads_conn_id: str = "facebook_ads_default",
+api_version: str = "v6.0",
+) -> None:
+super().__init__()
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.facebook_ads_config: Dict[str, Any] = {}
+self.api_version = api_version
+self.ad_account_id: str = ""
+self.app_id: str = ""
+self.app_secret: str = ""
+self.access_token: str = ""
 
 Review comment:
   Actually i'm removing these class attrs. Can be done without them.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-03-31 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r401215099
 
 

 ##
 File path: airflow/providers/facebook/ads/hooks/ads.py
 ##
 @@ -0,0 +1,150 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ads Reporting hooks
+"""
+import time
+from typing import Any, Dict, List, Optional
+
+from facebook_business.adobjects.adaccount import AdAccount
+from facebook_business.adobjects.adreportrun import AdReportRun
+from facebook_business.adobjects.adsinsights import AdsInsights
+from facebook_business.api import Cursor, FacebookAdsApi
+from facebook_business.exceptions import FacebookRequestError
+
+from airflow.exceptions import AirflowException
+from airflow.hooks.base_hook import BaseHook
+
+JOB_COMPLETED = 'Job Completed'
+
+
+class FacebookAdsReportingHook(BaseHook):
+"""
+Hook for the Facebook Ads API
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+
+:return: list of Facebook Ads AdsInsights object(s)
+:rtype: list[AdsInsights]
+"""
+
+def __init__(
+self,
+facebook_ads_conn_id: str = "facebook_ads_default",
+api_version: str = "v6.0",
+) -> None:
+super().__init__()
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.facebook_ads_config: Dict[str, Any] = {}
+self.api_version = api_version
+self.ad_account_id: str = ""
+self.app_id: str = ""
+self.app_secret: str = ""
+self.access_token: str = ""
+self.default_params = {
+'level': 'ad',
+'date_preset': 'yesterday',
+}
+
+def _get_service(self) -> FacebookAdsApi:
+""" Returns Facebook Ads Client using a service account"""
+self._get_config()
+for key, val in self.facebook_ads_config.items():
+setattr(self, key, val)
+
+return FacebookAdsApi.init(app_id=self.app_id,
 
 Review comment:
   Ya this can be done!


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] randr97 commented on a change in pull request #8008: Custom Facebook Ads Operator

2020-03-31 Thread GitBox
randr97 commented on a change in pull request #8008: Custom Facebook Ads 
Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r401213486
 
 

 ##
 File path: airflow/providers/facebook/ads/hooks/ads.py
 ##
 @@ -0,0 +1,150 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ads Reporting hooks
+"""
+import time
+from typing import Any, Dict, List, Optional
+
+from facebook_business.adobjects.adaccount import AdAccount
+from facebook_business.adobjects.adreportrun import AdReportRun
+from facebook_business.adobjects.adsinsights import AdsInsights
+from facebook_business.api import Cursor, FacebookAdsApi
+from facebook_business.exceptions import FacebookRequestError
+
+from airflow.exceptions import AirflowException
+from airflow.hooks.base_hook import BaseHook
+
+JOB_COMPLETED = 'Job Completed'
+
+
+class FacebookAdsReportingHook(BaseHook):
+"""
+Hook for the Facebook Ads API
+
+.. seealso::
+For more information on the Facebook Ads API, take a look at the API 
docs:
+https://developers.facebook.com/docs/marketing-apis/
+
+:param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+:type facebook_ads_conn_id: str
+:param api_version: The version of Facebook API. Default to v6.0
+:type api_version: str
+
+:return: list of Facebook Ads AdsInsights object(s)
+:rtype: list[AdsInsights]
+"""
+
+def __init__(
+self,
+facebook_ads_conn_id: str = "facebook_ads_default",
+api_version: str = "v6.0",
+) -> None:
+super().__init__()
+self.facebook_ads_conn_id = facebook_ads_conn_id
+self.facebook_ads_config: Dict[str, Any] = {}
+self.api_version = api_version
+self.ad_account_id: str = ""
+self.app_id: str = ""
+self.app_secret: str = ""
+self.access_token: str = ""
+self.default_params = {
+'level': 'ad',
+'date_preset': 'yesterday',
+}
+
+def _get_service(self) -> FacebookAdsApi:
+""" Returns Facebook Ads Client using a service account"""
+self._get_config()
+for key, val in self.facebook_ads_config.items():
 
 Review comment:
   Yep, will do so!


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services