Skip to content
Advertisement

503 Getting metadata from plugin failed with error: ‘GoogleRefreshTokenClient’ object has no attribute ‘before_request’ when trying to Upload clicks

client_id, client_secret, developer_token = settings.CLIENT_ID, settings.CLIENT_SECRET, settings.DEVELOPER_TOKEN

credentials = oauth2.GoogleRefreshTokenClient(
    client_id,
    client_secret,
    login_user.refresh_token
)

client = GoogleAdsClient(credentials, settings.DEVELOPER_TOKEN)

click_conversion = client.get_type("ClickConversion")
conversion_action_service = client.get_service("ConversionActionService")
click_conversion.conversion_action = (
    conversion_action_service.conversion_action_path(
        client_id, company.conversion_name
    )
)

click_conversion.gclid = deal.gclid
click_conversion.conversion_value = float(deal.deal_value if deal.deal_value else 0)
click_conversion.conversion_date_time = make_aware(datetime.now()).strftime('%Y%m%d %H%M%S %z')

conversion_upload_service = client.get_service("ConversionUploadService")
request = client.get_type("UploadClickConversionsRequest")
request.customer_id = client_id
request.conversions.append(click_conversion)
request.partial_failure = True
conversion_upload_response = (
    conversion_upload_service.upload_click_conversions(
        request=request,
    )
)

Does anyone know why I’m getting the above error when trying to Upload Clicks to google ads? got this in the logs:

Request made: ClientCustomerId: xxxxxx-xxxxx.apps.googleusercontent.com, Host: googleads.googleapis.com, Method: /google.ads.googleads.v11.services.ConversionUploadService/UploadClickConversions, RequestId: None, IsFault: True, FaultMessage: Getting metadata from plugin failed with error: ‘GoogleRefreshTokenClient’ object has no attribute ‘before_request’

Advertisement

Answer

It looks as if you’re using the googleads.oauth2.GoogleRefreshTokenClient class, which was the way to create credentials in the googleads package for the Adwords API.

This class is no longer in used for the google-ads (Ads API) package, use google.oauth2.credentials.Credentials instead.

The easiest way is to use the utility function google.ads.googleads.oauth2.get_installed_app_credentials():

credentials = google.ads.googleads.oauth2.get_installed_app_credentials(
    client_id=client_id, 
    client_secret=client_secret,
    refresh_token=login_user.refresh_token
)
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement