Updated AdSense Management API samples to V1.3
Reviewed in https://codereview.appspot.com/10382043/
This commit is contained in:
@@ -21,7 +21,7 @@ To get ad clients, run get_all_ad_clients.py.
|
||||
Tags: reports.generate
|
||||
"""
|
||||
|
||||
__author__ = 'sergio.gomes@google.com (Sergio Gomes)'
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
@@ -40,7 +40,7 @@ argparser.add_argument('report_id',
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
# Process flags and read their values.
|
||||
|
||||
@@ -46,7 +46,7 @@ argparser.add_argument('ad_client_id',
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
ad_client_id = flags.ad_client_id
|
||||
|
||||
@@ -21,7 +21,7 @@ This includes the full tree of sub-accounts.
|
||||
Tags: accounts.get
|
||||
"""
|
||||
|
||||
__author__ = 'sergio.gomes@google.com (Sergio Gomes)'
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
@@ -38,7 +38,7 @@ argparser.add_argument('account_id',
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
# Process flags and read their values.
|
||||
|
||||
@@ -32,7 +32,7 @@ MAX_PAGE_SIZE = 50
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
try:
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Tags: adclients.list
|
||||
"""
|
||||
|
||||
__author__ = 'sergio.gomes@google.com (Sergio Gomes)'
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
import sys
|
||||
|
||||
@@ -32,7 +32,7 @@ MAX_PAGE_SIZE = 50
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
try:
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Tags: accounts.adclients.list
|
||||
"""
|
||||
|
||||
__author__ = 'sergio.gomes@google.com (Sergio Gomes)'
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
@@ -38,7 +38,7 @@ argparser.add_argument('account_id',
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
account_id = flags.account_id
|
||||
|
||||
@@ -21,7 +21,7 @@ To get ad clients, run get_all_ad_clients.py.
|
||||
Tags: adunits.list
|
||||
"""
|
||||
|
||||
__author__ = 'sergio.gomes@google.com (Sergio Gomes)'
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
@@ -40,7 +40,7 @@ MAX_PAGE_SIZE = 50
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
ad_client_id = flags.ad_client_id
|
||||
|
||||
@@ -21,7 +21,7 @@ To get custom channels, run get_all_custom_channels.py.
|
||||
Tags: accounts.customchannels.adunits.list
|
||||
"""
|
||||
|
||||
__author__ = 'sergio.gomes@google.com (Sergio Gomes)'
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
@@ -34,7 +34,7 @@ argparser = argparse.ArgumentParser(add_help=False)
|
||||
argparser.add_argument('account_id',
|
||||
help='The ID of the account with the specified custom channel')
|
||||
argparser.add_argument('ad_client_id',
|
||||
help='The ID of the ad client for which to generate a report')
|
||||
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')
|
||||
|
||||
@@ -44,7 +44,7 @@ MAX_PAGE_SIZE = 50
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
# Process flags and read their values.
|
||||
|
||||
55
samples/adsense/get_all_alerts.py
Normal file
55
samples/adsense/get_all_alerts.py
Normal 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 default account.
|
||||
|
||||
Tags: metadata.alerts.list
|
||||
"""
|
||||
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
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, 'adsense', 'v1.3', __doc__, __file__, parents=[],
|
||||
scope='https://www.googleapis.com/auth/adsense.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)
|
||||
@@ -21,7 +21,7 @@ To get ad clients, run get_all_ad_clients.py.
|
||||
Tags: customchannels.list
|
||||
"""
|
||||
|
||||
__author__ = 'sergio.gomes@google.com (Sergio Gomes)'
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
@@ -40,7 +40,7 @@ MAX_PAGE_SIZE = 50
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
ad_client_id = flags.ad_client_id
|
||||
@@ -54,8 +54,8 @@ def main(argv):
|
||||
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']))
|
||||
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:'
|
||||
|
||||
@@ -22,8 +22,7 @@ get_all_ad_units.py.
|
||||
Tags: customchannels.list
|
||||
"""
|
||||
|
||||
__author__ = 'sergio.gomes@google.com (Sergio Gomes)'
|
||||
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
@@ -49,7 +48,7 @@ MAX_PAGE_SIZE = 50
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
# Process flags and read their values.
|
||||
@@ -85,7 +84,6 @@ def main(argv):
|
||||
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')
|
||||
|
||||
|
||||
55
samples/adsense/get_all_dimensions.py
Normal file
55
samples/adsense/get_all_dimensions.py
Normal 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 default account.
|
||||
|
||||
Tags: metadata.dimensions.list
|
||||
"""
|
||||
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
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, 'adsense', 'v1.3', __doc__, __file__, parents=[],
|
||||
scope='https://www.googleapis.com/auth/adsense.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)
|
||||
55
samples/adsense/get_all_metrics.py
Normal file
55
samples/adsense/get_all_metrics.py
Normal 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 default account.
|
||||
|
||||
Tags: metadata.metrics.list
|
||||
"""
|
||||
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
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, 'adsense', 'v1.3', __doc__, __file__, parents=[],
|
||||
scope='https://www.googleapis.com/auth/adsense.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)
|
||||
@@ -33,7 +33,7 @@ MAX_PAGE_SIZE = 50
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
try:
|
||||
|
||||
@@ -33,7 +33,7 @@ MAX_PAGE_SIZE = 50
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
try:
|
||||
|
||||
@@ -21,7 +21,7 @@ To get ad clients, run get_all_ad_clients.py.
|
||||
Tags: urlchannels.list
|
||||
"""
|
||||
|
||||
__author__ = 'sergio.gomes@google.com (Sergio Gomes)'
|
||||
__author__ = 'jalc@google.com (Jose Alcerreca)'
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
@@ -40,7 +40,7 @@ argparser.add_argument('ad_client_id',
|
||||
def main(argv):
|
||||
# Authenticate and construct service.
|
||||
service, flags = sample_tools.init(
|
||||
argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser],
|
||||
argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser],
|
||||
scope='https://www.googleapis.com/auth/adsense.readonly')
|
||||
|
||||
ad_client_id = flags.ad_client_id
|
||||
@@ -52,7 +52,6 @@ def main(argv):
|
||||
|
||||
while request is not None:
|
||||
result = request.execute()
|
||||
custom_channels = result['items']
|
||||
|
||||
url_channels = result['items']
|
||||
for url_channel in url_channels:
|
||||
|
||||
Reference in New Issue
Block a user