-
Notifications
You must be signed in to change notification settings - Fork 108
Release Notes
This release is mainly focused on following the recent Ads API version 6 release.
Several important changes are made in version 6 so please see the full details as to what's changed: https://twittercommunity.com/t/ads-api-version-6/129060
You can check all the SDK changes we made in this new release from this PR: https://github.com/twitterdev/twitter-python-ads-sdk/pull/223
We also updated the handy Postman collection (v6 support) to make your testing and development workflow even easier.
https://twittercommunity.com/t/ads-api-version-6/129060/1#heading--number-of-processing-jobs
In order to make it easier to manage asynchronous analytics workflows, the Ads API now returns two new response headers:
-
X-Concurrent-Job-Limit
: The maximum number of jobs that may be in a processing state at any given time -
X-Concurrent-Job-Limit-Remaining
: The number of jobs that can be created given the number currently being processed
These values are returned when asynchronous analytics jobs are created using the POST stats/jobs/accounts/:account_id endpoint, and SDK users can access these headers through instance variables:
stats = LineItem.queue_async_stats_job(account, ids, metric_groups)
print(stats.concurrent_job_limit)
print(stats.concurrent_job_limit_remaining)
This small new helper functionsplit_list()
can be used for splitting list
that contains entity ids by a given number.
from twitter_ads.utils import split_list
test_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(list(split_list(test_list, 2)))
# => [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]
promoted_tweets = PromotedTweet.all(account)
ids = list(map(lambda x: x.id, promoted_tweets))
sync_data = []
# Sync/Async endpoint can handle max 20 entity IDs per request
# so split the ids list into multiple requests
for chunk_ids in split_list(ids, 20):
sync_data.append(PromotedTweet.all_stats(account, chunk_ids, metric_groups))
print(sync_data)
-
Analytics.queue_async_stats_job()
can now be called directly (with specifying entity parameter) -
Analytics.queue_async_stats_job()
now returns instance rather than dict
- job_id = LineItem.queue_async_stats_job(account, ids, metric_groups)[id]
+ job_id = LineItem.queue_async_stats_job(account, ids, metric_groups).id
as_user_id
now required (commit)
https://twittercommunity.com/t/ads-api-version-6/129060/1#heading--as-user-id-now-required
Given the impact of this change, SDK now provides a new class method UserIdLookup.load()
that can be used to lookup an user_id by a Twitter screen name.
user_id = UserIdLookup.load(account, screen_name='your_twitter_handle_name').id
The GET accounts/:account_id/scoped_timeline endpoint is no longer available in v6 (commit).
https://twittercommunity.com/t/ads-api-version-6/129060/1#heading--scoped-timeline
* SDK will continue to support this endpoint until the v5 became sunset.
https://twittercommunity.com/t/announcement-audience-intelligence-deprecation/127907
Below endpoints are removed in this release:
- GET accounts/:account_id/tweet/preview
- GET accounts/:account_id/tweet/preview/:tweet_id
- GET accounts/:account_id/draft_tweets/preview/:draft_tweet_id
- GET accounts/:account_id/scheduled_tweets/preview/:scheduled_tweet_id
PR: #213
We're excited to announce that the Ads API Python SDK now supports rate-limit handling & request retry for the first time ever!:tada:
You can enable and try it out by setting following options:
client = Client(
CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN,
ACCESS_TOKEN_SECRET,
options={
'handle_rate_limit': True,
'retry_max': 3,
'retry_delay': 5000,
'retry_on_status': [404, 500, 503]
})
parameter | default | description |
---|---|---|
handle_rate_limit |
False (boolean) |
Set True will check rate-limit response header and sleep if the request reached the limit (429). |
retry_max |
0 (int) |
The number of times you want to retry when response code is found in retry_on_status . |
retry_delay |
1500 (int) |
The number of milliseconds you want to sleep before retry. |
retry_on_status |
[500, 503] (list) |
The response codes you want to retry on. You can only set >= 400 status codes. |
PR: #212
# return Cursor object
response = PromotedTweet.attach(
account,
line_item_id='aaaa',
tweet_ids=['111111111111111111', '222222222222222222' ... ]
)
Analytics.async_stats_job_result()
returns data through instance attributes (previously returned a list)
PR: https://github.com/twitterdev/twitter-python-ads-sdk/pull/211
Example:
async_stats_job_result = LineItem.async_stats_job_result(account, [job_id]).first
- async_data_url = LineItem.async_stats_job_data(account, async_stats_job_result['url'])
+ async_data = LineItem.async_stats_job_data(account, async_stats_job_result.url)