question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

provide dynamically loading client settings by object instead of using load_by_string

See original GitHub issue

Following the example, we need to make a yaml file to set client settings and use GoogleAdsClient.load_from_storage to create a new client instance, but it does not make sense in production service that provides multiple customers to fetch their ads.

My current solution is like this,

   configuration_string = '\n'.join([
        'developer_token: %s' % developer_token,
        'client_id: %s' % client_id,
        'client_secret: %s' % client_secret,
        'refresh_token: %s' % refresh_token,
        'login_customer_id: %s' % login_customer_id
    ])
    client = google.ads.google_ads.client.GoogleAdsClient.load_from_string(configuration_string)

I use GoogleAdsClient.load_from_string to make a string as yaml format, but I think it had better provide a function to load settings by dictionary(object), and it will be more easy to use.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
BenRKarlcommented, Apr 3, 2019

@yo8568 Thanks for that info, it does make sense. I’ll keep this issue open as a feature request to add a method load_from_dict that allows the client to receive a dict of credentials.

In the meantime you can sort-of achieve this by initializing the client directly. You’ll need to import the OAuth client and create a set of Credentials through it, like so (we do this here in the client):

from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
from google.ads.google_ads.client import GoogleAdsClient
 
credentials = Credentials(
    None,
    refresh_token=refresh_token,
    client_id=client_id,
    client_secret=client_secret,
    token_uri='https://accounts.google.com/o/oauth2/token')

credentials.refresh(Request())

client = GoogleAdsClient(credentials, developer_token, login_customer_id=login_customer_id)

You can reference the initialization method here to see what other keyword parameters are available.

0reactions
BenRKarlcommented, Jul 17, 2019

#139 was merged and release in library version 3.1.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load dynamic objects from application.properties in Spring Boot
This is how you can load dynamic objects from application.properties in Spring Boot with Kotlin: Suppose you have an object class called ...
Read more >
changelog.txt - GitHub
... rewriters not recognizing WP Offload Media Path (object prefix) setting ... Lazy Load picture elements use right-sized img placeholder instead of 1x1 ......
Read more >
Configuring dynamic client registration settings
Go to System → OAuth Settings → Client Settings and click Dynamic Client Registration. Select the check boxes for the options that you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found