Skip to content

Commit cdafd01

Browse files
committed
Google Ad Manager rebrand & v201808 release
1 parent ea5a264 commit cdafd01

File tree

1,367 files changed

+44162
-44022
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,367 files changed

+44162
-44022
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Follow either of the two links above to access the appropriate CLA and instructi
1313
- Sign a Contributor License Agreement (see above).
1414
- Join the appropriate product discussion forum.
1515
- AdWords API: https://developers.google.com/adwords/api/community/
16-
- DFP API: https://developers.google.com/doubleclick-publishers/community
17-
- DFA API: https://developers.google.com/doubleclick-advertisers/reporting/community
16+
- Ad Manager API: https://developers.google.com/ad-manager/community
1817
- Create an issue on the library issue tracker if there isn't one already. Use this issue to co-ordinate the changes with the library maintainer.
1918
- Fork the library, make the changes and send a [pull request](https://help.github.com/articles/using-pull-requests).
2019
- The library maintainer will work with you to review and apply the patch.

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
14.0.0 -- 08/21/18
2+
- DFP rebranded to Google Ad Manager.
3+
- Google Ad Manager v201808 release.
4+
- Removed support for DFP v201708.
5+
- Removed examples for DFP v201711.
6+
17
13.0.0 -- 07/25/18
28
- Removed support for AdWords v201710.
39

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# The googleads Python client library
22

3+
**Note:** DoubleClick for Publishers was recently renamed to Google Ad Manager, and this library
4+
was modified to follow suit. Please see the [migration guide](https://github.com/googleads/googleads-python-lib/wiki/dfp-rebrand)
5+
for more details.
36

47
This client library simplifies accessing Google's SOAP Ads APIs - AdWords,
58
and DoubleClick for Publishers. The library provides easy ways to store your
@@ -40,19 +43,19 @@ code to help you get started integrating with our APIs.
4043
**If you're accessing an API using your own credentials...**
4144

4245
* [Using AdWords](https://github.com/googleads/googleads-python-lib/wiki/API-access-using-own-credentials-(installed-application-flow))
43-
* [Using DFP](https://github.com/googleads/googleads-python-lib/wiki/API-access-using-own-credentials-(server-to-server-flow))
46+
* [Using Ad Manager](https://github.com/googleads/googleads-python-lib/wiki/API-access-using-own-credentials-(server-to-server-flow))
4447

4548
**If you're accessing an API on behalf of clients...**
4649

47-
* [Developing a web application (AdWords or DFP)](https://github.com/googleads/googleads-python-lib/wiki/API-access-on-behalf-of-your-clients-(web-flow))
50+
* [Developing a web application (AdWords or Ad Manager)](https://github.com/googleads/googleads-python-lib/wiki/API-access-on-behalf-of-your-clients-(web-flow))
4851

4952
#### Where can I find samples?
5053

51-
You can find code examples for the latest versions of AdWords or DFP on the
54+
You can find code examples for the latest versions of AdWords or Ad Manager on the
5255
[releases](https://github.com/googleads/googleads-python-lib/releases) page.
5356

5457
Alternatively, you can find [AdWords](https://github.com/googleads/googleads-python-lib/tree/master/examples/adwords)
55-
or [DFP](https://github.com/googleads/googleads-python-lib/tree/master/examples/dfp)
58+
or [Ad Manager](https://github.com/googleads/googleads-python-lib/tree/master/examples/ad_manager)
5659
samples in the examples directory of this repository.
5760

5861
#### Where can I find the pydocs?
@@ -73,7 +76,7 @@ contents.
7376
adwords_client = adwords.AdWordsClient.LoadFromStorage()
7477

7578
# Alternatively, pass in the location of the file:
76-
dfp_client = dfp.DfpClient.LoadFromStorage('C:\My\Directory\googleads.yaml')
79+
ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage('C:\My\Directory\googleads.yaml')
7780
```
7881

7982
#### How do I change the Client Customer Id at runtime?
@@ -200,7 +203,7 @@ access a local file system that may not be available in certain hosting
200203
environments such as App Engine.
201204

202205
You can pass an implementation of `suds.cache.Cache` or `zeep.cache.Base` to the `AdWordsClient` or
203-
`DfpClient` initializer to modify the default caching behavior.
206+
`AdManagerClient` initializer to modify the default caching behavior.
204207

205208
For example, configuring a different location and duration of the cache file with zeep
206209
```python
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2017 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Initializes an AdManagerClient using GoogleAccessTokenClient.
18+
19+
Note that unlike clients initialized with GoogleRefreshTokenClient, those
20+
initialized with GoogleAccessTokenClient can't refresh.
21+
"""
22+
23+
import argparse
24+
import datetime
25+
from googleads import ad_manager
26+
from googleads import oauth2
27+
import httplib2
28+
from oauth2client import client
29+
30+
31+
GOOGLE_OAUTH2_ENDPOINT = 'https://accounts.google.com/o/oauth2/token'
32+
USER_AGENT = 'INSERT_USER_AGENT_HERE'
33+
34+
# OAuth2 credential information.
35+
DEFAULT_CLIENT_ID = 'INSERT_CLIENT_ID_HERE'
36+
DEFAULT_CLIENT_SECRET = 'INSERT_CLIENT_SECRET_HERE'
37+
DEFAULT_REFRESH_TOKEN = 'INSERT_REFRESH_TOKEN_HERE'
38+
39+
# Ad Manager API information.
40+
DEFAULT_APPLICATION_NAME = 'INSERT_APPLICATION_NAME_HERE'
41+
42+
parser = argparse.ArgumentParser(
43+
description=('Creates an AdManagerClient using a GoogleAccessToken with an '
44+
'access token generated with the given credentials.'))
45+
parser.add_argument('--client_id', default=DEFAULT_CLIENT_ID,
46+
help='Client Id retrieved from the Developer\'s Console.')
47+
parser.add_argument('--client_secret', default=DEFAULT_CLIENT_SECRET,
48+
help='Client Secret retrieved from the Developer\'s '
49+
'Console.')
50+
parser.add_argument('--refresh_token', default=DEFAULT_REFRESH_TOKEN,
51+
help='The refresh token used to generate an access token.')
52+
parser.add_argument('--application_name', default=DEFAULT_APPLICATION_NAME,
53+
help='The application name for your Ad Manager account.')
54+
55+
56+
def main(access_token, token_expiry, application_name):
57+
oauth2_client = oauth2.GoogleAccessTokenClient(access_token, token_expiry)
58+
59+
ad_manager_client = ad_manager.AdManagerClient(
60+
oauth2_client, application_name)
61+
62+
networks = ad_manager_client.GetService('NetworkService').getAllNetworks()
63+
for network in networks:
64+
print ('Network with network code "%s" and display name "%s" was found.'
65+
% (network['networkCode'], network['displayName']))
66+
67+
68+
if __name__ == '__main__':
69+
args = parser.parse_args()
70+
71+
# Retrieve a new access token for use in this example. In a production
72+
# application, you may use a credential store to share access tokens for a
73+
# given user across applications.
74+
oauth2credentials = client.OAuth2Credentials(
75+
None, args.client_id, args.client_secret, args.refresh_token,
76+
datetime.datetime(1980, 1, 1, 12), GOOGLE_OAUTH2_ENDPOINT,
77+
USER_AGENT)
78+
79+
oauth2credentials.refresh(httplib2.Http())
80+
81+
main(oauth2credentials.access_token, oauth2credentials.token_expiry,
82+
args.application_name)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2014 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Initializes a AdManagerClient without using yaml-cached credentials.
18+
19+
While our LoadFromStorage method provides a useful shortcut to instantiate a
20+
client if you regularly use just one set of credentials, production applications
21+
may need to swap out users. This example shows you how to create an OAuth2
22+
client and a AdManagerClient without relying on a yaml file.
23+
"""
24+
25+
26+
from googleads import ad_manager
27+
from googleads import oauth2
28+
29+
# OAuth2 credential information. In a real application, you'd probably be
30+
# pulling these values from a credential storage.
31+
CLIENT_ID = 'INSERT_CLIENT_ID_HERE'
32+
CLIENT_SECRET = 'INSERT_CLIENT_SECRET_HERE'
33+
REFRESH_TOKEN = 'INSERT_REFRESH_TOKEN_HERE'
34+
35+
# Ad Manager API information.
36+
APPLICATION_NAME = 'INSERT_APPLICATION_NAME_HERE'
37+
38+
39+
def main(client_id, client_secret, refresh_token, application_name):
40+
oauth2_client = oauth2.GoogleRefreshTokenClient(
41+
client_id, client_secret, refresh_token)
42+
43+
ad_manager_client = ad_manager.AdManagerClient(
44+
oauth2_client, application_name)
45+
46+
networks = ad_manager_client.GetService('NetworkService').getAllNetworks()
47+
for network in networks:
48+
print ('Network with network code "%s" and display name "%s" was found.'
49+
% (network['networkCode'], network['displayName']))
50+
51+
52+
if __name__ == '__main__':
53+
main(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN, APPLICATION_NAME)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2014 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Initializes a AdManagerClient using a Service Account."""
18+
19+
20+
from googleads import ad_manager
21+
from googleads import oauth2
22+
23+
# OAuth2 credential information. In a real application, you'd probably be
24+
# pulling these values from a credential storage.
25+
KEY_FILE = 'INSERT_KEY_FILE_PATH'
26+
27+
# Ad Manager API information.
28+
APPLICATION_NAME = 'INSERT_APPLICATION_NAME_HERE'
29+
30+
31+
def main(key_file, application_name):
32+
oauth2_client = oauth2.GoogleServiceAccountClient(
33+
key_file, oauth2.GetAPIScope('ad_manager'))
34+
35+
ad_manager_client = ad_manager.AdManagerClient(
36+
oauth2_client, application_name)
37+
38+
networks = ad_manager_client.GetService('NetworkService').getAllNetworks()
39+
for network in networks:
40+
print ('Network with network code "%s" and display name "%s" was found.'
41+
% (network['networkCode'], network['displayName']))
42+
43+
44+
if __name__ == '__main__':
45+
main(KEY_FILE, APPLICATION_NAME)

examples/dfp/authentication/generate_refresh_token.py renamed to examples/ad_manager/authentication/generate_refresh_token.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
"""Generates a refresh token for use with DFP."""
17+
"""Generates a refresh token for use with Ad Manager."""
1818

1919

2020
import argparse
@@ -28,7 +28,7 @@
2828
DEFAULT_CLIENT_ID = None
2929
DEFAULT_CLIENT_SECRET = None
3030

31-
# The DFP API OAuth2 scope.
31+
# The Ad Manager API OAuth2 scope.
3232
SCOPE = u'https://www.googleapis.com/auth/dfp'
3333
# The redirect URI set for the given Client ID. The redirect URI for Client ID
3434
# generated for an installed application will always have this value.
@@ -95,7 +95,7 @@ def main(client_id, client_secret, scopes):
9595

9696
auth_url, _ = flow.authorization_url(prompt='consent')
9797

98-
print ('Log into the Google Account you use to access your DFP account'
98+
print ('Log into the Google Account you use to access your Ad Manager account'
9999
'and go to the following URL: \n%s\n' % (auth_url))
100100
print 'After approving the token enter the verification code (if specified).'
101101
code = raw_input('Code: ').strip()

examples/dfp/v201711/activity_group_service/__init__.py renamed to examples/ad_manager/v201802/activity_group_service/__init__.py

File renamed without changes.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2015 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""This code example creates new activity groups.
18+
19+
To determine which activity groups exist, run get_all_activity_groups.py.
20+
21+
The LoadFromStorage method is pulling credentials and properties from a
22+
"googleads.yaml" file. By default, it looks for this file in your home
23+
directory. For more information, see the "Caching authentication information"
24+
section of our README.
25+
26+
"""
27+
28+
29+
import uuid
30+
31+
# Import appropriate modules from the client library.
32+
from googleads import ad_manager
33+
34+
# Set the ID of the advertiser company this activity group is associated with.
35+
ADVERTISER_COMPANY_ID = 'INSERT_ADVERTISER_COMPANY_ID_HERE'
36+
37+
38+
def main(client, advertiser_company_id):
39+
# Initialize appropriate service.
40+
activity_group_service = client.GetService('ActivityGroupService',
41+
version='v201802')
42+
43+
# Create a short-term activity group.
44+
short_term_activity_group = {
45+
'name': 'Short-term activity group #%s' % uuid.uuid4(),
46+
'companyIds': [advertiser_company_id],
47+
'clicksLookback': '1',
48+
'impressionsLookback': '1'
49+
}
50+
51+
# Create a long-term activity group.
52+
long_term_activity_group = {
53+
'name': 'Long-term activity group #%s' % uuid.uuid4(),
54+
'companyIds': [advertiser_company_id],
55+
'clicksLookback': '30',
56+
'impressionsLookback': '30'
57+
}
58+
59+
# Create the activity groups on the server.
60+
activity_groups = activity_group_service.createActivityGroups([
61+
short_term_activity_group, long_term_activity_group])
62+
63+
# Display results.
64+
for activity_group in activity_groups:
65+
print ('Activity group with ID "%s" and name "%s" was created.'
66+
% (activity_group['id'], activity_group['name']))
67+
68+
if __name__ == '__main__':
69+
# Initialize client object.
70+
ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage()
71+
main(ad_manager_client, ADVERTISER_COMPANY_ID)

0 commit comments

Comments
 (0)