การกําหนดค่าพร็อกซี

หากต้องการเชื่อมต่อกับ Google Ads API ผ่านพร็อกซี HTTP หรือ HTTPS คุณสามารถกำหนดค่าการตั้งค่า http_proxy ในไฟล์การกำหนดค่า ผ่านโปรแกรม หรือผ่านตัวแปรสภาพแวดล้อม การตั้งค่า http_proxy มีผลกับช่องทางการรับส่งข้อมูล gRPC ที่ไลบรารีของไคลเอ็นต์ Python ใช้

กำหนดค่าโดยใช้ google-ads.yaml

ระบุการตั้งค่า http_proxy ในไฟล์ google-ads.yaml โดยทำดังนี้

# Optional proxy configuration used for API requests. If your proxy does not
# require authentication, specify only the host and port.
http_proxy: INSERT_PROXY_HERE

เช่น คุณระบุ http://user:pass@localhost:8082 เป็นพร็อกซีได้

กำหนดค่าผ่านโปรแกรม

นอกจากนี้ คุณยังกำหนดค่าการตั้งค่าพร็อกซีผ่านโปรแกรมได้โดยใช้เมธอดการเริ่มต้น GoogleAdsClient (load_from_dict, load_from_env และ load_from_string) เช่นเดียวกับการตั้งค่าการกำหนดค่าอื่นๆ

from google.ads.googleads.client import GoogleAdsClient

config = {
    # Include other required configuration settings here.
    "http_proxy": "INSERT_PROXY_HERE",
}
googleads_client = GoogleAdsClient.load_from_dict(config)

กำหนดค่าโดยใช้ตัวแปรสภาพแวดล้อม

หากต้องการกำหนดค่าพร็อกซีด้วยเมธอด load_from_env ให้ตั้งค่าตัวแปรสภาพแวดล้อม GOOGLE_ADS_HTTP_PROXY ดังนี้

export GOOGLE_ADS_HTTP_PROXY="http://user:pass@localhost:8082"