Esempio n. 1
0
def get_auth_token(client):
    """Authenticate with Criteo Marketing API and return acccess token."""
    LOGGER.info("Getting OAuth token")
    auth_api = criteo_marketing.AuthenticationApi()
    with singer.metrics.http_request_timer("Authentication"):
        auth_response = auth_api.o_auth2_token_post(
            client_id=client.configuration.username,
            client_secret=client.configuration.password,
            grant_type=GRANT_TYPE,
        )
    global TOKEN_EXPIRE
    TOKEN_EXPIRE = get_unixtime() + auth_response.expires_in
    # Token type is always "BEARER"
    return auth_response.token_type + " " + auth_response.access_token
# There is only one accepted GRANT_TYPE
GRANT_TYPE = 'client_credentials'

if __name__ == '__main__':
    if len(sys.argv) != 3:
        raise ValueError(
            "You need to specify the CLIENT_ID and the CLIENT_SECRET")

    configuration = Configuration(username=sys.argv[1], password=sys.argv[2])

    # Enable/Disable debug httplib and criteo_marketing packages
    # logging.basicConfig(level=logging.DEBUG)
    # configuration.debug = True

    client = criteo_marketing.ApiClient(configuration)

    # Get a valid token. The configuration is accessible through the client
    auth_api = criteo_marketing.AuthenticationApi(client)
    auth_response = auth_api.o_auth2_token_post(
        client_id=client.configuration.username,
        client_secret=client.configuration.password,
        grant_type=GRANT_TYPE)
    # Token type is always "BEARER"
    token = auth_response.token_type + " " + auth_response.access_token

    # Reuse the same client to benefit from the configuration in order to automatically refresh expired token
    portfolio_api = criteo_marketing.PortfolioApi(client)

    portfolio_response = portfolio_api.get_portfolio(token)
    pprint(portfolio_response)
Esempio n. 3
0
    return ((pd.to_datetime(string_date).weekday() - 1) % 7)


def tuesday_week(string_date):
    date_diff = (pd.to_datetime(string_date).weekday() - 1) % 7
    return (str(pd.to_datetime(string_date) - timedelta(date_diff))[:10])


import time
import criteo_marketing
from criteo_marketing.rest import ApiException
from pprint import pprint
import requests

# Create an instance of the API class
api_instance = criteo_marketing.AuthenticationApi()

# Criteo creds
with open('criteo_creds.json') as json_file:
    criteo_creds = json.load(json_file)

# Write all creds
client_id = criteo_creds['client_id']
client_secret = criteo_creds['client_secret']
grant_type = criteo_creds['grant_type']

try:
    # Authenticates provided credentials and returns an access token
    api_response = api_instance.o_auth2_token_post(client_id=client_id,
                                                   client_secret=client_secret,
                                                   grant_type=grant_type)
Esempio n. 4
0
import sys

import criteo_marketing as cm
from criteo_marketing import Configuration

GRANT_TYPE = 'client_credentials'

if __name__ == '__main__':
    if len(sys.argv) != 3:
        raise ValueError("You need to specify the CLIENT_ID and the CLIENT_SECRET")

    configuration = Configuration(username=sys.argv[1], password=sys.argv[2])

    client = cm.ApiClient(configuration)

    auth_api = cm.AuthenticationApi(client)
    auth_response = auth_api.o_auth2_token_post(client_id=client.configuration.username,
                                                client_secret=client.configuration.password,
                                                grant_type=GRANT_TYPE)
    token = auth_response.token_type + " " + auth_response.access_token

    stats_api = cm.StatisticsApi(client)
    stats_query_message = cm.StatsQueryMessageEx(
        report_type="CampaignPerformance",
        dimensions=["CampaignId"],
        metrics=["Clicks"],
        start_date="2019-01-01",
        end_date="2019-01-31",
        format="Csv")

    # Use the method with 'with_http_info' if you want to retrieve the filename