Skip to content

Commit

Permalink
update to version 12.13.2
Browse files Browse the repository at this point in the history
  • Loading branch information
qitia committed May 15, 2019
1 parent 218cf3f commit 9da0783
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 23 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
.. :changelog:
Release History
-----------
12.13.2(2019-05-15)
+++++++++++++++++++
* IMPORTANT: The default OAuth endpoint is updated from "Live Connect": https://docs.microsoft.com/en-us/advertising/guides/authentication-oauth-live-connect endpoint to the "Microsoft Identity endpoint for developers": https://docs.microsoft.com/en-us/advertising/guides/authentication-oauth-identity-platform. The "Microsoft Identity endpoint" supports both Microsoft Account (MSA) personal credentials and Azure Active Directory (AAD) work credentials. For more information, see "Upgrade to the Microsoft identity platform endpoint FAQ": https://docs.microsoft.com/en-us/advertising/guides/authentication-oauth#upgrade-identity-platform-faq.
* Updated Bing Ads API version 12 and 13 service proxies to reflect recent interface changes. For details please see the "Bing Ads API Release Notes": https://docs.microsoft.com/en-us/bingads/guides/release-notes.
* For Bing Ads API version 12 and 13, added a new Bulk property for Final Url Suffix phase 2 entities i.e., added FinalUrlSuffix to the existing BulkActionAdExtension, BulkAppAdExtension, BulkImageAdExtension, BulkPriceAdExtension, BulkSitelinkAdExtension, BulkAdGroupProductPartition, and BulkAd. For details see "Final Url Suffix": https://docs.microsoft.com/en-us/advertising/guides/url-tracking-upgraded-urls#finalurlsuffixvalidation.


-----------
12.13.1(2019-04-15)
+++++++++++++++++++
Expand Down
55 changes: 34 additions & 21 deletions bingads/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class OAuthAuthorization(Authentication):
* :class:`.OAuthWebAuthCodeGrant`
"""

def __init__(self, client_id, oauth_tokens=None, env=PRODUCTION):
def __init__(self, client_id, oauth_tokens=None, env=PRODUCTION, require_live_connect=False):
""" Initializes a new instance of the OAuthAuthorization class.
:param client_id: The client identifier corresponding to your registered application.
Expand All @@ -279,6 +279,7 @@ def __init__(self, client_id, oauth_tokens=None, env=PRODUCTION):
self._oauth_tokens = oauth_tokens
self._state = None
self.environment=env
self._require_live_connect=require_live_connect

@property
def client_id(self):
Expand Down Expand Up @@ -353,7 +354,7 @@ class OAuthWithAuthorizationCode(OAuthAuthorization):
For more information about registering a Bing Ads application, see http://go.microsoft.com/fwlink/?LinkID=511607.
"""

def __init__(self, client_id, client_secret, redirection_uri, token_refreshed_callback=None, oauth_tokens=None, env=PRODUCTION):
def __init__(self, client_id, client_secret, redirection_uri, token_refreshed_callback=None, oauth_tokens=None, env=PRODUCTION, require_live_connect=False):
""" Initialize a new instance of this class.
:param client_id: The client identifier corresponding to your registered application.
Expand All @@ -370,7 +371,7 @@ def __init__(self, client_id, client_secret, redirection_uri, token_refreshed_ca
:return:
"""

super(OAuthWithAuthorizationCode, self).__init__(client_id, oauth_tokens=oauth_tokens, env=env)
super(OAuthWithAuthorizationCode, self).__init__(client_id, oauth_tokens=oauth_tokens, env=env, require_live_connect=require_live_connect)
self._client_secret = client_secret
self._redirection_uri = redirection_uri
self._token_refreshed_callback = token_refreshed_callback
Expand All @@ -382,7 +383,7 @@ def get_authorization_endpoint(self):
:rtype: str
"""
endpoint = str.format(
_UriOAuthService.AUTHORIZE_URI[self.environment],
_UriOAuthService.AUTHORIZE_URI[(self.environment, self._require_live_connect)],
self._client_id,
'code',
quote_plus(self._redirection_uri)
Expand Down Expand Up @@ -417,6 +418,7 @@ def request_oauth_tokens_by_response_uri(self, response_uri):
grant_type='authorization_code',
environment=self.environment,
code=code,
requireliveconnect=self._require_live_connect
)
if self.token_refreshed_callback is not None:
self.token_refreshed_callback(self.oauth_tokens) # invoke the callback when token refreshed.
Expand All @@ -438,11 +440,11 @@ def request_oauth_tokens_by_refresh_token(self, refresh_token):
self._oauth_tokens = _UriOAuthService.get_access_token(
client_id=self.client_id,
client_secret=self.client_secret,
redirect_uri=self.redirection_uri,
grant_type='refresh_token',
refresh_token=refresh_token,
environment=self.environment,
scope='bingads.manage',
scope=_UriOAuthService.SCOPE[(self.environment, self._require_live_connect)],
requireliveconnect=self._require_live_connect
)
if self.token_refreshed_callback is not None:
self.token_refreshed_callback(self.oauth_tokens) # invoke the callback when token refreshed.
Expand Down Expand Up @@ -503,7 +505,7 @@ class OAuthDesktopMobileAuthCodeGrant(OAuthWithAuthorizationCode):
For more information about registering a Bing Ads application, see http://go.microsoft.com/fwlink/?LinkID=511607.
"""

def __init__(self, client_id, oauth_tokens=None, env=PRODUCTION):
def __init__(self, client_id, oauth_tokens=None, env=PRODUCTION, require_live_connect=False):
""" Initializes a new instance of the this class with the specified client id.
:param client_id: The client identifier corresponding to your registered application.
Expand All @@ -515,9 +517,10 @@ def __init__(self, client_id, oauth_tokens=None, env=PRODUCTION):
super(OAuthDesktopMobileAuthCodeGrant, self).__init__(
client_id,
None,
_UriOAuthService.REDIRECTION_URI[env],
_UriOAuthService.REDIRECTION_URI[(env, require_live_connect)],
oauth_tokens=oauth_tokens,
env=env
env=env,
require_live_connect=require_live_connect
)


Expand Down Expand Up @@ -551,7 +554,7 @@ class OAuthDesktopMobileImplicitGrant(OAuthAuthorization):
"""


def __init__(self, client_id, oauth_tokens=None, env=PRODUCTION):
def __init__(self, client_id, oauth_tokens=None, env=PRODUCTION, require_live_connect=False):
""" Initializes a new instance of the this class with the specified client id.
:param client_id: The client identifier corresponding to your registered application.
Expand All @@ -560,7 +563,7 @@ def __init__(self, client_id, oauth_tokens=None, env=PRODUCTION):
:type oauth_tokens: OAuthTokens
"""

super(OAuthDesktopMobileImplicitGrant, self).__init__(client_id, oauth_tokens=oauth_tokens, env=env)
super(OAuthDesktopMobileImplicitGrant, self).__init__(client_id, oauth_tokens=oauth_tokens, env=env, require_live_connect=require_live_connect)



Expand All @@ -572,10 +575,10 @@ def get_authorization_endpoint(self):
"""

endpoint = str.format(
_UriOAuthService.AUTHORIZE_URI[self.environment],
_UriOAuthService.AUTHORIZE_URI[(self.environment, self._require_live_connect)],
self.client_id,
'token',
_UriOAuthService.REDIRECTION_URI[self.environment],
_UriOAuthService.REDIRECTION_URI[(self.environment, self._require_live_connect)],
)
return endpoint if self.state is None else endpoint + '&state=' + self.state

Expand Down Expand Up @@ -604,7 +607,7 @@ def extract_access_token_from_uri(self, redirection_uri):

@property
def redirection_uri(self):
return _UriOAuthService.REDIRECTION_URI[self.environment]
return _UriOAuthService.REDIRECTION_URI[(self.environment, self._require_live_connect)]


class _UriOAuthService:
Expand All @@ -613,12 +616,22 @@ class _UriOAuthService:
def __init__(self):
pass

REDIRECTION_URI={PRODUCTION:'https://login.live.com/oauth20_desktop.srf',
SANDBOX:'https://login.live-int.com/oauth20_desktop.srf'}
AUTH_TOKEN_URI={PRODUCTION:'https://login.live.com/oauth20_token.srf',
SANDBOX:'https://login.live-int.com/oauth20_token.srf'}
AUTHORIZE_URI={PRODUCTION:'https://login.live.com/oauth20_authorize.srf?client_id={0}&scope=bingads.manage&response_type={1}&redirect_uri={2}',
SANDBOX:'https://login.live-int.com/oauth20_authorize.srf?client_id={0}&scope=bingads.manage&response_type={1}&redirect_uri={2}&prompt=login'}
REDIRECTION_URI={(PRODUCTION, True):'https://login.live.com/oauth20_desktop.srf',
(PRODUCTION, False):'https://login.microsoftonline.com/common/oauth2/nativeclient',
(SANDBOX, False):'https://login.live-int.com/oauth20_desktop.srf'
}
AUTH_TOKEN_URI={(PRODUCTION, True):'https://login.live.com/oauth20_token.srf',
(PRODUCTION, False):'https://login.microsoftonline.com/common/oauth2/v2.0/token',
(SANDBOX, False):'https://login.live-int.com/oauth20_token.srf'
}
AUTHORIZE_URI={(PRODUCTION, True):'https://login.live.com/oauth20_authorize.srf?client_id={0}&scope=bingads.manage&response_type={1}&redirect_uri={2}',
(PRODUCTION, False):'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={0}&scope=https%3A%2F%2Fads.microsoft.com%2Fads.manage%20offline_access&response_type={1}&redirect_uri={2}',
(SANDBOX, False):'https://login.live-int.com/oauth20_authorize.srf?client_id={0}&scope=bingads.manage&response_type={1}&redirect_uri={2}&prompt=login'
}
SCOPE={(PRODUCTION, True):'bingads.manage',
(PRODUCTION, False):'https://ads.microsoft.com/ads.manage offline_access',
(SANDBOX, False):'bingads.manage'
}

@staticmethod
def get_access_token(**kwargs):
Expand All @@ -633,7 +646,7 @@ def get_access_token(**kwargs):
if 'client_secret' in kwargs and kwargs['client_secret'] is None:
del kwargs['client_secret']

r = requests.post(_UriOAuthService.AUTH_TOKEN_URI[kwargs['environment']], kwargs, verify=True)
r = requests.post(_UriOAuthService.AUTH_TOKEN_URI[(kwargs['environment'], kwargs['requireliveconnect'])], kwargs, verify=True)
try:
r.raise_for_status()
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion bingads/manifest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
VERSION = '12.13.1'
VERSION = '12.13.2'
BULK_FORMAT_VERSION_5 = '5.0'
BULK_FORMAT_VERSION_6 = '6.0'
WORKING_NAME = 'BingAdsSDKPython'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def action_text(self, value):
field_to_csv=lambda c: c.action_text,
csv_to_field=lambda c, v: setattr(c, 'action_text', v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.action_ad_extension.FinalUrlSuffix, c.action_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.action_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def app_ad_extension(self, value):
field_to_csv=lambda c: c.app_ad_extension.DisplayText,
csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'DisplayText', v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.app_ad_extension.FinalUrlSuffix, c.app_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def image_ad_extension(self, value):
#csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'ImageMediaIds', int(v))
csv_to_field=lambda c, v: csv_to_field_MediaIds(c.image_ad_extension, v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.image_ad_extension.FinalUrlSuffix, c.image_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def price_ad_extension(self, value):
entity_to_csv=lambda c, v: entity_to_csv_PriceTableRows(c.price_ad_extension, v),
csv_to_entity=lambda v, c: csv_to_entity_PriceTableRows(v, c.price_ad_extension)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.price_ad_extension.FinalUrlSuffix, c.price_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def sitelink_ad_extension(self, value):
field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.sitelink_ad_extension),
csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.sitelink_ad_extension, v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.sitelink_ad_extension.FinalUrlSuffix, c.sitelink_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
5 changes: 5 additions & 0 deletions bingads/v12/bulk/entities/bulk_ad_group_product_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ def _read_destination_url(cls, entity, row_value):
csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.ad_group_criterion, v)
if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.ad_group_criterion.FinalUrlSuffix, c.ad_group_criterion.Id) if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None ,
csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'FinalUrlSuffix', v) if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None
)
]

@property
Expand Down
5 changes: 5 additions & 0 deletions bingads/v12/bulk/entities/bulk_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ def performance_data(self):
field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.ad),
csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.ad, v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.ad.FinalUrlSuffix, c.ad.Id),
csv_to_field=lambda c, v: setattr(c.ad, 'FinalUrlSuffix', v)
)
]

def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
Expand Down
8 changes: 8 additions & 0 deletions bingads/v12/proxies/campaign_management_service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@
<xs:element minOccurs="0" name="Path1" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Path2" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Text" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="TextPart2" nillable="true" type="xs:string">
<xs:annotation>
<xs:appinfo>
<DefaultValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/" EmitDefaultValue="false" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
Expand Down Expand Up @@ -1195,6 +1202,7 @@
<xs:enumeration value="TextPart2" />
<xs:enumeration value="Images" />
<xs:enumeration value="FinalUrlSuffix" />
<xs:enumeration value="TextPart2DSA" />
</xs:restriction>
</xs:simpleType>
</xs:list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def action_text(self, value):
field_to_csv=lambda c: c.action_text,
csv_to_field=lambda c, v: setattr(c, 'action_text', v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.action_ad_extension.FinalUrlSuffix, c.action_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.action_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def app_ad_extension(self, value):
field_to_csv=lambda c: c.app_ad_extension.DisplayText,
csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'DisplayText', v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.app_ad_extension.FinalUrlSuffix, c.app_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.app_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def image_ad_extension(self, value):
#csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'ImageMediaIds', int(v))
csv_to_field=lambda c, v: csv_to_field_MediaIds(c.image_ad_extension, v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.image_ad_extension.FinalUrlSuffix, c.image_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.image_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def price_ad_extension(self, value):
entity_to_csv=lambda c, v: entity_to_csv_PriceTableRows(c.price_ad_extension, v),
csv_to_entity=lambda v, c: csv_to_entity_PriceTableRows(v, c.price_ad_extension)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.price_ad_extension.FinalUrlSuffix, c.price_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.price_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def sitelink_ad_extension(self, value):
field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.sitelink_ad_extension),
csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.sitelink_ad_extension, v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.sitelink_ad_extension.FinalUrlSuffix, c.sitelink_ad_extension.Id),
csv_to_field=lambda c, v: setattr(c.sitelink_ad_extension, 'FinalUrlSuffix', v)
)
]

def process_mappings_from_row_values(self, row_values):
Expand Down
5 changes: 5 additions & 0 deletions bingads/v13/bulk/entities/bulk_ad_group_product_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ def _read_destination_url(cls, entity, row_value):
csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.ad_group_criterion, v)
if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.ad_group_criterion.FinalUrlSuffix, c.ad_group_criterion.Id) if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None ,
csv_to_field=lambda c, v: setattr(c.ad_group_criterion, 'FinalUrlSuffix', v) if isinstance(c.ad_group_criterion, _BiddableAdGroupCriterion) else None
)
]

@property
Expand Down
5 changes: 5 additions & 0 deletions bingads/v13/bulk/entities/bulk_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ def ad(self, ad):
field_to_csv=lambda c: field_to_csv_UrlCustomParameters(c.ad),
csv_to_field=lambda c, v: csv_to_field_UrlCustomParameters(c.ad, v)
),
_SimpleBulkMapping(
header=_StringTable.FinalUrlSuffix,
field_to_csv=lambda c: bulk_optional_str(c.ad.FinalUrlSuffix, c.ad.Id),
csv_to_field=lambda c, v: setattr(c.ad, 'FinalUrlSuffix', v)
)
]

def process_mappings_to_row_values(self, row_values, exclude_readonly_data):
Expand Down
Loading

0 comments on commit 9da0783

Please sign in to comment.