How to upload image file FROM Google Cloud Bucket TO Campaign Manager 360

I have a Cloud Function (CF) which is getting TRIGGERED after a file is copied into GCS. The aim is copy this media file in Campaign Manager 360.
I have my oAuth 2.0 Credential created which i want to use ( after the ‘flow’ statement. ) But my CF fails saying “Name: client is not defined”

And although the last part of the 5-6 lines of code is me just trying to list something, the actual aim in THAT PART is to upload a media file, which is currently in GCS, into Campaign Manager 360. How do i POST it to CM360, from within the CF ?

https://developers.google.com/doubleclick-advertisers/upload?hl=en

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import functions_framework
import json
import hashlib
from flask import abort
# Triggered by a change in a storage bucket
@functions_framework.cloud_event
def creative_to_gcs(cloud_event):
data = cloud_event.data
event_id = cloud_event["id"]
event_type = cloud_event["type"]
bucket = data["bucket"]
name = data["name"]
metageneration = data["metageneration"]
timeCreated = data["timeCreated"]
updated = data["updated"]
print(f"Event ID: {event_id}")
print(f"Event type: {event_type}")
print(f"Bucket: {bucket}")
print(f"File: {name}")
print(f"Metageneration: {metageneration}")
print(f"Created: {timeCreated}")
print(f"Updated: {updated}")
flow = client.flow_from_clientsecrets(path_to_client_secrets_file, scope=OAUTH_SCOPES)
storage = Storage(CREDENTIAL_STORE_FILE)
credentials = storage.get()
# If no credentials were found, go through the authorization process and
# persist credentials to the credential store.
if credentials is None or credentials.invalid:
credentials = tools.run_flow(flow, storage, tools.argparser.parse_known_args()[0])
# Use the credentials to authorize an httplib2.Http instance.
http = credentials.authorize(httplib2.Http())
# Construct a service object via the discovery service.
service = discovery.build('dfareporting', 'v4', http=http)
# Construct the request.
request = service.userProfiles().list()
# Execute request and print response.
response = request.execute()
for profile in response['items']:
print('Found user profile with ID %s and user name "%s".' %(profile['profileId'], profile['userName'])) ```
</code>
<code>import functions_framework import json import hashlib from flask import abort # Triggered by a change in a storage bucket @functions_framework.cloud_event def creative_to_gcs(cloud_event): data = cloud_event.data event_id = cloud_event["id"] event_type = cloud_event["type"] bucket = data["bucket"] name = data["name"] metageneration = data["metageneration"] timeCreated = data["timeCreated"] updated = data["updated"] print(f"Event ID: {event_id}") print(f"Event type: {event_type}") print(f"Bucket: {bucket}") print(f"File: {name}") print(f"Metageneration: {metageneration}") print(f"Created: {timeCreated}") print(f"Updated: {updated}") flow = client.flow_from_clientsecrets(path_to_client_secrets_file, scope=OAUTH_SCOPES) storage = Storage(CREDENTIAL_STORE_FILE) credentials = storage.get() # If no credentials were found, go through the authorization process and # persist credentials to the credential store. if credentials is None or credentials.invalid: credentials = tools.run_flow(flow, storage, tools.argparser.parse_known_args()[0]) # Use the credentials to authorize an httplib2.Http instance. http = credentials.authorize(httplib2.Http()) # Construct a service object via the discovery service. service = discovery.build('dfareporting', 'v4', http=http) # Construct the request. request = service.userProfiles().list() # Execute request and print response. response = request.execute() for profile in response['items']: print('Found user profile with ID %s and user name "%s".' %(profile['profileId'], profile['userName'])) ``` </code>
import functions_framework
import json
import hashlib
from flask import abort

# Triggered by a change in a storage bucket
@functions_framework.cloud_event
def creative_to_gcs(cloud_event):
    data = cloud_event.data

    event_id = cloud_event["id"]
    event_type = cloud_event["type"]

    bucket = data["bucket"]
    name = data["name"]
    metageneration = data["metageneration"]
    timeCreated = data["timeCreated"]
    updated = data["updated"]

    print(f"Event ID: {event_id}")
    print(f"Event type: {event_type}")
    print(f"Bucket: {bucket}")
    print(f"File: {name}")
    print(f"Metageneration: {metageneration}")
    print(f"Created: {timeCreated}")
    print(f"Updated: {updated}")

    flow = client.flow_from_clientsecrets(path_to_client_secrets_file, scope=OAUTH_SCOPES)
    storage = Storage(CREDENTIAL_STORE_FILE)
    credentials = storage.get()

# If no credentials were found, go through the authorization process and
# persist credentials to the credential store.
    if credentials is None or credentials.invalid:
      credentials = tools.run_flow(flow, storage, tools.argparser.parse_known_args()[0])

# Use the credentials to authorize an httplib2.Http instance.
    http = credentials.authorize(httplib2.Http())

# Construct a service object via the discovery service.
    service = discovery.build('dfareporting', 'v4', http=http)

# Construct the request.
    request = service.userProfiles().list()

# Execute request and print response.
    response = request.execute()

    for profile in response['items']:
      print('Found user profile with ID %s and user name "%s".' %(profile['profileId'], profile['userName']))    ```

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật