Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3638

Get backfill reports for past dates using Youtube Analytics and Reporting API

$
0
0

What we have: We have our own reporting database for a Youtube content owner to monitor performance of our Youtube channels. We have an ETL job that pulls latest reports everyday of type content_owner_basic_a3.

What the problem is: Since Youtube removes invalid views from the past dates (e.g., views associated with bots and scrapers). The numbers in our database are always higher than those in Youtube Analytics platform.

What we want: Since Youtube automatically generates backfill data reports that update the metrics for a past date, we would also like to download such backfill reports and update metrics in our own database. However, no such backfill reports are available where video metrics have been updated. Here's how we are accessing it:

from google_auth_oauthlib.flow import InstalledAppFlowfrom googleapiclient.discovery import buildimport argparseCLIENT_SECRETS_FILE = "client_secret.json"SCOPES = NoneAPI_SERVICE_NAME = "youtubereporting"API_VERSION = "v1"# Authorize the request and store authorization credentials.def get_authenticated_service():    flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)    credentials = flow.run_console()    return build(API_SERVICE_NAME, API_VERSION, credentials=credentials)if __name__ == "__main__":    parser = argparse.ArgumentParser()    parser.add_argument("--content_owner",        default="",        help="ID of content owner for which you are retrieving jobs and reports",    )    parser.add_argument("--job_id",        default=None,        help="job ID for job with reportTypeId: content_owner_basic_a3",    )    args = parser.parse_args()    youtube_reporting = get_authenticated_service()    created_after = "2023-06-22T00:00:00.00Z"    results = (        youtube_reporting.jobs()        .reports()        .list(            jobId=args.job_id,            onBehalfOfContentOwner=args.content_owner,            createdAfter=created_after,        )        .execute()    )

Is there a different way to update the past metrics? Or are we missing something in our implementation?


Viewing all articles
Browse latest Browse all 3638

Trending Articles