Package: twitter-ads-v2
Getting StartedInstallation# install the latest releasepipinstalltwitter-ads-v2Quick Startimporttwitter_ads_v2CONSUMER_KEY='your consumer key'CONSUMER_SECRET='your consumer secret'ACCESS_TOKEN='access token'ACCESS_TOKEN_SECRET='access token secret'ACCOUNT_ID='account id'client=twitter_ads_v2.Client(ACCOUNT_ID,CONSUMER_KEY,CONSUMER_SECRET,ACCESS_TOKEN,ACCESS_TOKEN_SECRET,options={'handle_rate_limit':True})# indexdata=client.campaigns('all')print(data.headers)print(data.body)# showdata=client.campaigns('load',id='campaign_id')print(data.headers)print(data.body)tweets=client.promoted_tweets('all')# iterate over until the cursor ("next_cursor") is exhaustedforiintweets:print(i.headers)print(i.body)Types ofendpoint_typeTo provide a consistent interface, the first parameter of each API method is alwaysendpoint_type:data=client.campaigns('load',id='campaign_id')in the above example,loadis theendpoint_typeof this call. The terms of eachendpoint_typeare described below.endpoint_typedescriptionHTTP methodallRetrieveallorsomeof the entities’ details depends on the request parameters from an index endpoint (i.e., most index endpoints have a parameter that can scope the results).GETloadRetrieve aspecificentity details from a show endpoint (i.e., most show endpoints require an entity id to retrieve as part of resource URI).GETcreateCreate a new entity.POSTupdateUpdate a specific entity.PUTdeleteDelete a specific entity.DELETEbatchCreate/Update/Delete entities depends on the POST body data (normally a JSON object).POSTRequest ParametersAll request parameters exceptendpoint_typeas mentioned above should be passed as keyword arguments.Rate-limit handling and request retryclient=twitter_ads_v2.Client(ACCOUNT_ID,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]})parameterdefaultdescriptionhandle_rate_limitFalse(boolean)SetTruewill check the rate-limit response header and sleep if the request reached the limit (429).retry_max0(int)The number of times you want to retry when response code is found inretry_on_status.retry_delay1500(int)The number ofmillisecondsyou 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.Compatibility & VersioningThis project is designed to work with Python 3.5 or greater. While it may work on other versions of Python, below are the platform and runtime versions we officially support and regularly test against.PlatformVersionsCPython3.5, 3.6, 3.7PyPy7.xAll releases adhere to strict semantic versioning. For Example, major.minor.patch-pre (aka. stick.carrot.oops-peek).DevelopmentIf you’d like to contribute to the project or try an unreleased development version of this project locally, you can do so quite easily by following the examples below.# clone the repositorygitclonegit@github.com:smaeda-ks/twitter-python-ads-sdk-v2.gitcdtwitter-python-ads-sdk-v2# installing a local unsigned releasepipinstall-e.Tests$pythonsetup.pyflake8&&pythonsetup.pytestDocumentationIf you’d like to contribute to the project's documentation, you need to setup Sphinx and build pages by the following steps.# install dependencies$pipinstall-e.[doc]# build pages$cdsphinx/
$makeclean&&makehtml