Adding Ad Exchange Seller REST API samples.

This commit is contained in:
sgomes@google.com
2013-10-10 17:48:22 +01:00
parent 959d241c71
commit 4d50cd6883
15 changed files with 915 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
A collection of command-line samples for the Ad Exchange Seller REST API.
api: adexchangeseller
keywords: cmdline
author: Sérgio Gomes (sgomes@google.com)

View File

@@ -0,0 +1,9 @@
{
"installed": {
"client_id": "[[INSERT CLIENT ID HERE]]",
"client_secret": "[[INSERT CLIENT SECRET HERE]]",
"redirect_uris": [],
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token"
}
}

View File

@@ -0,0 +1,85 @@
#!/usr/bin/python
#
# Copyright 2013 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.
"""Retrieves a saved report, or a report for the specified ad client.
To get ad clients, run get_all_ad_clients.py.
Tags: reports.generate
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument(
'--ad_client_id',
help='The ID of the ad client for which to generate a report')
argparser.add_argument(
'--report_id',
help='The ID of the saved report to generate')
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
# Process flags and read their values.
ad_client_id = flags.ad_client_id
saved_report_id = flags.report_id
try:
# Retrieve report.
if saved_report_id:
result = service.reports().saved().generate(
savedReportId=saved_report_id).execute()
elif ad_client_id:
result = service.reports().generate(
startDate='2011-01-01', endDate='2011-08-31',
filter=['AD_CLIENT_ID==' + ad_client_id],
metric=['PAGE_VIEWS', 'AD_REQUESTS', 'AD_REQUESTS_COVERAGE',
'CLICKS', 'AD_REQUESTS_CTR', 'COST_PER_CLICK',
'AD_REQUESTS_RPM', 'EARNINGS'],
dimension=['DATE'],
sort=['+DATE']).execute()
else:
argparser.print_help()
sys.exit(1)
# Display headers.
for header in result['headers']:
print '%25s' % header['name'],
print
# Display results.
for row in result['rows']:
for column in row:
print '%25s' % column,
print
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,99 @@
#!/usr/bin/python
#
# Copyright 2013 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 retrieves a report for the specified ad client.
Please only use pagination if your application requires it due to memory or
storage constraints.
If you need to retrieve more than 5000 rows, please check generate_report.py, as
due to current limitations you will not be able to use paging for large reports.
To get ad clients, run get_all_ad_clients.py.
Tags: reports.generate
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
MAX_PAGE_SIZE = 50
# This is the maximum number of obtainable rows for paged reports.
ROW_LIMIT = 5000
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('ad_client_id',
help='The ID of the ad client for which to generate a report')
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
ad_client_id = flags.ad_client_id
try:
# Retrieve report in pages and display data as we receive it.
start_index = 0
rows_to_obtain = MAX_PAGE_SIZE
while True:
result = service.reports().generate(
startDate='2011-01-01', endDate='2011-08-31',
filter=['AD_CLIENT_ID==' + ad_client_id],
metric=['PAGE_VIEWS', 'AD_REQUESTS', 'AD_REQUESTS_COVERAGE',
'CLICKS', 'AD_REQUESTS_CTR', 'COST_PER_CLICK',
'AD_REQUESTS_RPM', 'EARNINGS'],
dimension=['DATE'],
sort=['+DATE'],
startIndex=start_index,
maxResults=rows_to_obtain).execute()
# If this is the first page, display the headers.
if start_index == 0:
for header in result['headers']:
print '%25s' % header['name'],
print
# Display results for this page.
for row in result['rows']:
for column in row:
print '%25s' % column,
print
start_index += len(result['rows'])
# Check to see if we're going to go above the limit and get as many
# results as we can.
if start_index + MAX_PAGE_SIZE > ROW_LIMIT:
rows_to_obtain = ROW_LIMIT - start_index
if rows_to_obtain <= 0:
break
if (start_index >= int(result['totalMatchedRows'])):
break
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,59 @@
#!/usr/bin/python
#
# Copyright 2013 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 ad clients for the logged in user's account.
Tags: adclients.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import sys
from apiclient import sample_tools
from oauth2client import client
MAX_PAGE_SIZE = 50
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
try:
# Retrieve ad client list in pages and display data as we receive it.
request = service.adclients().list(maxResults=MAX_PAGE_SIZE)
while request is not None:
result = request.execute()
ad_clients = result['items']
for ad_client in ad_clients:
print ('Ad client for product "%s" with ID "%s" was found. '
% (ad_client['productCode'], ad_client['id']))
print ('\tSupports reporting: %s' %
(ad_client['supportsReporting'] and 'Yes' or 'No'))
request = service.adclients().list_next(request, result)
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,67 @@
#!/usr/bin/python
#
# Copyright 2013 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 ad units in an ad client.
To get ad clients, run get_all_ad_clients.py.
Tags: adunits.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('ad_client_id',
help='The ID of the ad client for which to generate a report')
MAX_PAGE_SIZE = 50
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
ad_client_id = flags.ad_client_id
try:
# Retrieve ad unit list in pages and display data as we receive it.
request = service.adunits().list(adClientId=ad_client_id,
maxResults=MAX_PAGE_SIZE)
while request is not None:
result = request.execute()
ad_units = result['items']
for ad_unit in ad_units:
print ('Ad unit with code "%s", name "%s" and status "%s" was found. ' %
(ad_unit['code'], ad_unit['name'], ad_unit['status']))
request = service.adunits().list_next(request, result)
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,72 @@
#!/usr/bin/python
#
# Copyright 2013 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 ad units corresponding to a specified custom channel.
To get custom channels, run get_all_custom_channels.py.
Tags: customchannels.adunits.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('ad_client_id',
help='The ID of the ad client with the specified custom channel')
argparser.add_argument('custom_channel_id',
help='The ID of the custom channel for which to get ad units')
MAX_PAGE_SIZE = 50
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
# Process flags and read their values.
ad_client_id = flags.ad_client_id
custom_channel_id = flags.custom_channel_id
try:
# Retrieve ad unit list in pages and display data as we receive it.
request = service.customchannels().adunits().list(
adClientId=ad_client_id, customChannelId=custom_channel_id,
maxResults=MAX_PAGE_SIZE)
while request is not None:
result = request.execute()
ad_units = result['items']
for ad_unit in ad_units:
print ('Ad unit with code "%s", name "%s" and status "%s" was found. ' %
(ad_unit['code'], ad_unit['name'], ad_unit['status']))
request = service.adunits().list_next(request, result)
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,55 @@
#!/usr/bin/python
#
# Copyright 2013 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.
"""Gets all alerts available for the logged in user's account.
Tags: alerts.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
try:
# Retrieve alerts list in pages and display data as we receive it.
request = service.alerts().list()
if request is not None:
result = request.execute()
if 'items' in result:
alerts = result['items']
for alert in alerts:
print ('Alert id "%s" with severity "%s" and type "%s" was found. '
% (alert['id'], alert['severity'], alert['type']))
else:
print 'No alerts found!'
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,79 @@
#!/usr/bin/python
#
# Copyright 2013 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 custom channels in an ad client.
To get ad clients, run get_all_ad_clients.py.
Tags: customchannels.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('ad_client_id',
help='The ad client ID for which to get custom channels')
MAX_PAGE_SIZE = 50
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
ad_client_id = flags.ad_client_id
try:
# Retrieve custom channel list in pages and display data as we receive it.
request = service.customchannels().list(adClientId=ad_client_id,
maxResults=MAX_PAGE_SIZE)
while request is not None:
result = request.execute()
custom_channels = result['items']
for custom_channel in custom_channels:
print ('Custom channel with id "%s" and name "%s" was found. '
% (custom_channel['id'], custom_channel['name']))
if 'targetingInfo' in custom_channel:
print ' Targeting info:'
targeting_info = custom_channel['targetingInfo']
if 'adsAppearOn' in targeting_info:
print ' Ads appear on: %s' % targeting_info['adsAppearOn']
if 'location' in targeting_info:
print ' Location: %s' % targeting_info['location']
if 'description' in targeting_info:
print ' Description: %s' % targeting_info['description']
if 'siteLanguage' in targeting_info:
print ' Site language: %s' % targeting_info['siteLanguage']
request = service.customchannels().list_next(request, result)
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,87 @@
#!/usr/bin/python
#
# Copyright 2013 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 custom channels an ad unit has been added to.
To get ad clients, run get_all_ad_clients.py. To get ad units, run
get_all_ad_units.py.
Tags: customchannels.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument(
'ad_client_id',
help='The ID of the ad client with the specified ad unit')
argparser.add_argument(
'ad_unit_id',
help='The ID of the ad unit for which to get custom channels')
MAX_PAGE_SIZE = 50
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
# Process flags and read their values.
ad_client_id = flags.ad_client_id
ad_unit_id = flags.ad_unit_id
try:
# Retrieve custom channel list in pages and display data as we receive it.
request = service.adunits().customchannels().list(
adClientId=ad_client_id, adUnitId=ad_unit_id,
maxResults=MAX_PAGE_SIZE)
while request is not None:
result = request.execute()
custom_channels = result['items']
for custom_channel in custom_channels:
print ('Custom channel with code "%s" and name "%s" was found. '
% (custom_channel['code'], custom_channel['name']))
if 'targetingInfo' in custom_channel:
print ' Targeting info:'
targeting_info = custom_channel['targetingInfo']
if 'adsAppearOn' in targeting_info:
print ' Ads appear on: %s' % targeting_info['adsAppearOn']
if 'location' in targeting_info:
print ' Location: %s' % targeting_info['location']
if 'description' in targeting_info:
print ' Description: %s' % targeting_info['description']
if 'siteLanguage' in targeting_info:
print ' Site language: %s' % targeting_info['siteLanguage']
request = service.customchannels().list_next(request, result)
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,55 @@
#!/usr/bin/python
#
# Copyright 2013 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.
"""Gets all dimensions available for the logged in user's account.
Tags: metadata.dimensions.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
try:
# Retrieve metrics list in pages and display data as we receive it.
request = service.metadata().dimensions().list()
if request is not None:
result = request.execute()
if 'items' in result:
dimensions = result['items']
for dimension in dimensions:
print ('Dimension id "%s" for product(s): [%s] was found. '
% (dimension['id'], ', '.join(dimension['supportedProducts'])))
else:
print 'No dimensions found!'
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,55 @@
#!/usr/bin/python
#
# Copyright 2013 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.
"""Gets all metrics available for the logged in user's account.
Tags: metadata.metrics.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
try:
# Retrieve metrics list in pages and display data as we receive it.
request = service.metadata().metrics().list()
if request is not None:
result = request.execute()
if 'items' in result:
metrics = result['items']
for metric in metrics:
print ('Metric id "%s" for product(s): [%s] was found. '
% (metric['id'], ', '.join(metric['supportedProducts'])))
else:
print 'No metrics found!'
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,63 @@
#!/usr/bin/python
#
# Copyright 2013 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.
"""Gets all preferred deals for the logged in user's account.
Tags: preferreddeals.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
try:
# Retrieve preferred deals list in pages and display data as we receive it.
request = service.preferreddeals().list()
if request is not None:
result = request.execute()
if 'items' in result:
deals = result['items']
for deal in deals:
output = 'Deal id "%s" ' % deal['id']
if 'advertiserName' in deal:
output += 'for advertiser "%s" ' % deal['advertiserName']
if 'buyerNetworkName' in deal:
output += 'on network "%s" ' % deal['buyerNetworkName']
output += 'was found.'
print(output)
else:
print 'No preferred deals found!'
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,57 @@
#!/usr/bin/python
#
# Copyright 2013 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 the saved reports for the logged
in user's default account.
Tags: savedreports.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import sys
from apiclient import sample_tools
from oauth2client import client
MAX_PAGE_SIZE = 50
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
try:
# Retrieve ad client list in pages and display data as we receive it.
request = service.reports().saved().list(maxResults=MAX_PAGE_SIZE)
while request is not None:
result = request.execute()
saved_reports = result['items']
for saved_report in saved_reports:
print ('Saved report with ID "%s" and name "%s" was found.'
% (saved_report['id'], saved_report['name']))
request = service.reports().saved().list_next(request, result)
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)

View File

@@ -0,0 +1,68 @@
#!/usr/bin/python
#
# Copyright 2013 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 URL channels in an ad client.
To get ad clients, run get_all_ad_clients.py.
Tags: urlchannels.list
"""
__author__ = 'sgomes@google.com (Sérgio Gomes)'
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
MAX_PAGE_SIZE = 50
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('ad_client_id',
help='The ad client ID for which to get URL channels')
def main(argv):
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
ad_client_id = flags.ad_client_id
try:
# Retrieve URL channel list in pages and display data as we receive it.
request = service.urlchannels().list(adClientId=ad_client_id,
maxResults=MAX_PAGE_SIZE)
while request is not None:
result = request.execute()
url_channels = result['items']
for url_channel in url_channels:
print ('URL channel with URL pattern "%s" was found.'
% url_channel['urlPattern'])
request = service.customchannels().list_next(request, result)
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')
if __name__ == '__main__':
main(sys.argv)