-
Notifications
You must be signed in to change notification settings - Fork 975
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b93ae8e
commit aeb1176
Showing
22 changed files
with
4,276 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
examples/dfp/v201708/live_stream_event_service/activate_live_stream_events.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2018 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""This code example activates paused live stream events.""" | ||
|
||
# Import appropriate modules from the client library. | ||
from googleads import dfp | ||
|
||
# Set the id of the LiveStreamEvent to get live stream events from. | ||
LIVE_STREAM_EVENT_ID = 'INSERT_LIVE_STREAM_EVENT_ID_HERE' | ||
|
||
|
||
def main(client, live_stream_event_id): | ||
# Initialize appropriate service. | ||
live_stream_event_service = client.GetService( | ||
'LiveStreamEventService', version='v201708') | ||
|
||
# Create query to find paused live stream events. | ||
statement = (dfp.StatementBuilder() | ||
.Where(('id = :id AND ' | ||
'status = :status')) | ||
.WithBindVariable('status', 'PAUSED') | ||
.WithBindVariable('id', long(live_stream_event_id)) | ||
.Limit(500)) | ||
|
||
live_stream_events_activated = 0 | ||
|
||
# Get live stream events by statement. | ||
while True: | ||
response = live_stream_event_service.getLiveStreamEventsByStatement( | ||
statement.ToStatement()) | ||
if 'results' in response: | ||
for live_stream_event in response['results']: | ||
print('live stream event with id "%s" and name "%s" will be activated.' | ||
% (live_stream_event['id'], live_stream_event['name'])) | ||
|
||
# Perform action. | ||
result = live_stream_event_service.performLiveStreamEventAction({ | ||
'xsi_type': 'ActivateLiveStreamEvents' | ||
}, statement.ToStatement()) | ||
if result and int(result['numChanges']) > 0: | ||
live_stream_events_activated += int(result['numChanges']) | ||
statement.offset += dfp.SUGGESTED_PAGE_LIMIT | ||
else: | ||
break | ||
|
||
# Display results. | ||
if live_stream_events_activated > 0: | ||
print '# of live stream events activated: %s' % ( | ||
live_stream_events_activated) | ||
else: | ||
print 'No live stream events were activated.' | ||
|
||
|
||
if __name__ == '__main__': | ||
# Initialize client object. | ||
dfp_client = dfp.DfpClient.LoadFromStorage() | ||
main(dfp_client, LIVE_STREAM_EVENT_ID) |
68 changes: 68 additions & 0 deletions
68
examples/dfp/v201708/live_stream_event_service/create_live_stream_events.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2018 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""This code example creates new live stream events. | ||
To determine which live stream events exist, run get_all_live_stream_events.py. | ||
To determine which cdn configurations exist, run get_cdn_configurations.py. | ||
""" | ||
|
||
import datetime | ||
import uuid | ||
|
||
# Import appropriate modules from the client library. | ||
from googleads import dfp | ||
import pytz | ||
|
||
# Set content urls and adTags to use | ||
CONTENT_URLS = ['INSERT_CONTENT_URLS_HERE'] | ||
AD_TAGS = ['INSERT_AD_TAGS_HERE'] | ||
|
||
|
||
def main(client, content_urls, ad_tags): | ||
# Initialize appropriate services. | ||
live_events_service = client.GetService( | ||
'LiveStreamEventService', version='v201708') | ||
|
||
# Stream will play for 365 days | ||
start_datetime = datetime.datetime.now(tz=pytz.timezone('America/New_York')) | ||
end_datetime = start_datetime + datetime.timedelta(days=365) | ||
|
||
# Create live stream event objects | ||
live_stream_events = [{ | ||
'name': 'Live Stream Event #%s' % uuid.uuid4(), | ||
'startDateTime': start_datetime, | ||
'endDateTime': end_datetime, | ||
'contentUrls': content_urls, | ||
'adTags': ad_tags | ||
}] | ||
|
||
# Add live stream events. | ||
live_stream_events = live_events_service.createLiveStreamEvents( | ||
live_stream_events) | ||
|
||
# Display results. | ||
for live_stream_event in live_stream_events: | ||
print( | ||
'Live stream event with id "%s", named "%s" and status %s was created.' | ||
% (live_stream_event['id'], live_stream_event['name'], | ||
live_stream_event['status'])) | ||
|
||
|
||
if __name__ == '__main__': | ||
# Initialize client object. | ||
dfp_client = dfp.DfpClient.LoadFromStorage() | ||
main(dfp_client, CONTENT_URLS, AD_TAGS) |
52 changes: 52 additions & 0 deletions
52
examples/dfp/v201708/live_stream_event_service/get_all_live_stream_events.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2018 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""This example gets all live stream events. | ||
""" | ||
|
||
# Import appropriate modules from the client library. | ||
from googleads import dfp | ||
|
||
|
||
def main(client): | ||
# Initialize appropriate service. | ||
live_stream_event_service = client.GetService( | ||
'LiveStreamEventService', version='v201708') | ||
|
||
# Create a statement to select live stream events. | ||
statement = dfp.StatementBuilder() | ||
|
||
# Retrieve a small amount of live stream events at a time, paging | ||
# through until all live stream events have been retrieved. | ||
while True: | ||
response = live_stream_event_service.getLiveStreamEventsByStatement( | ||
statement.ToStatement()) | ||
if 'results' in response: | ||
for live_stream_event in response['results']: | ||
# Print out some information for each live stream event. | ||
print('live stream event with id "%d" and name "%s" was found.' % | ||
(live_stream_event['id'], live_stream_event['name'])) | ||
statement.offset += statement.limit | ||
else: | ||
break | ||
|
||
print '\nNumber of results found: %s' % response['totalResultSetSize'] | ||
|
||
|
||
if __name__ == '__main__': | ||
# Initialize client object. | ||
dfp_client = dfp.DfpClient.LoadFromStorage() | ||
main(dfp_client) |
45 changes: 45 additions & 0 deletions
45
examples/dfp/v201708/live_stream_event_service/register_sessions_for_monitoring.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2018 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""This example registers all live stream event-sessions ids for monitoring.""" | ||
|
||
# Import appropriate modules from the client library. | ||
from googleads import dfp | ||
|
||
# List of session ids | ||
SESSION_IDS = ['INSERT_SESSION_IDS_HERE'] | ||
|
||
|
||
def main(client, session_ids): | ||
# Initialize appropriate service. | ||
live_stream_event_service = client.GetService( | ||
'LiveStreamEventService', version='v201708') | ||
|
||
# Retrieve all sessions id that are being monitored | ||
session_ids = live_stream_event_service.registerSessionsForMonitoring( | ||
session_ids) | ||
if session_ids: | ||
for session_id in session_ids: | ||
# Print out some information for each live stream event. | ||
print 'Session with ID "%s" registered for monitoring.' % (session_id) | ||
|
||
print '\nNumber of results found: %s' % session_ids.size | ||
|
||
|
||
if __name__ == '__main__': | ||
# Initialize client object. | ||
dfp_client = dfp.DfpClient.LoadFromStorage() | ||
main(dfp_client, SESSION_IDS) |
69 changes: 69 additions & 0 deletions
69
examples/dfp/v201708/live_stream_event_service/update_live_stream_events.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2018 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""This code example updates live stream events. | ||
To determine which live stream events exist, run get_all_live_stream_events.py. | ||
""" | ||
|
||
# Import appropriate modules from the client library. | ||
from googleads import dfp | ||
|
||
# Set ID of the LiveStreamEvent to get live stream events from. | ||
LIVE_STREAM_EVENT_ID = 'INSERT_LIVE_STREAM_EVENT_ID_HERE' | ||
|
||
|
||
def main(client, live_stream_event_id): | ||
# Initialize appropriate services. | ||
live_stream_events_service = client.GetService( | ||
'LiveStreamEventService', version='v201708') | ||
|
||
# Create statement object to only select matching live stream event. | ||
statement = (dfp.StatementBuilder() | ||
.Where(('Id = :id')) | ||
.WithBindVariable('id', long(live_stream_event_id)) | ||
.Limit(500)) | ||
|
||
# Get live stream events by statement. | ||
response = live_stream_events_service.getLiveStreamEventsByStatement( | ||
statement.ToStatement()) | ||
|
||
# Set adTags to be updated. | ||
new_ad_tags = ['INSERT_NEW_AD_TAGS_HERE'] | ||
|
||
if 'results' in response: | ||
# Update each local live stream event by changing its attributes. | ||
updated_live_stream_events = [] | ||
for live_stream_event in response['results']: | ||
live_stream_event['startDateTimeType'] = 'IMMEDIATELY' | ||
live_stream_event['adTags'] = new_ad_tags | ||
updated_live_stream_events.append(live_stream_event) | ||
|
||
# Update live stream events. | ||
live_stream_events = live_stream_events_service.updateLiveStreamEvents( | ||
updated_live_stream_events) | ||
|
||
# Display results. | ||
for live_stream_event in live_stream_events: | ||
print('Live stream event with id "%s", named "%s" and status %s was ' | ||
'updated.' % (live_stream_event['id'], live_stream_event['name'], | ||
live_stream_event['status'])) | ||
|
||
|
||
if __name__ == '__main__': | ||
# Initialize client object. | ||
dfp_client = dfp.DfpClient.LoadFromStorage() | ||
main(dfp_client, LIVE_STREAM_EVENT_ID) |
Oops, something went wrong.