Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no report data for the submitted report request parameters. #277

Open
Beyond-me opened this issue Apr 10, 2024 · 0 comments
Open

Comments

@Beyond-me
Copy link

Beyond-me commented Apr 10, 2024

When I run the code to obtain the account performance report, it prompts There is no report data for the submitted report request parameters
Where did I go wrong? What should I do?


from auth_helper import *
from bingads import AuthorizationData
from bingads.v13.reporting import *
from output_helper import output_bing_ads_webfault_error, output_webfault_errors, output_status_message
from auth_helper import authenticate

REPORT_FILE_FORMAT='Csv'
FILE_DIRECTORY='reports'
RESULT_FILE_NAME='result.' + REPORT_FILE_FORMAT.lower()
TIMEOUT_IN_MILLISECONDS=3600000

def main(authorization_data):
# try:
# You can submit one of the example reports, or build your own.

    report_request=get_report_request(authorization_data.account_id)

    reporting_download_parameters = ReportingDownloadParameters(
        report_request=report_request,
        result_file_directory = FILE_DIRECTORY,
        result_file_name = RESULT_FILE_NAME,
        overwrite_result_file = True, # Set this value true if you want to overwrite the same file.
        timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS # You may optionally cancel the download after a specified time interval.
    )

    output_status_message("-----\nAwaiting download_report...")
    download_report(reporting_download_parameters)

def background_completion(reporting_download_parameters):
""" You can submit a download request and the ReportingServiceManager will automatically
return results. The ReportingServiceManager abstracts the details of checking for result file
completion, and you don't have to write any code for results polling. """

global reporting_service_manager
result_file_path = reporting_service_manager.download_file(reporting_download_parameters)
output_status_message("Download result file: {0}".format(result_file_path))

def submit_and_download(report_request):
""" Submit the download request and then use the ReportingDownloadOperation result to
track status until the report is complete e.g. either using
ReportingDownloadOperation.track() or ReportingDownloadOperation.get_status(). """

global reporting_service_manager
reporting_download_operation = reporting_service_manager.submit_download(report_request)

# You may optionally cancel the track() operation after a specified time interval.
reporting_operation_status = reporting_download_operation.track(timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS)

result_file_path = reporting_download_operation.download_result_file(
    result_file_directory = FILE_DIRECTORY,
    result_file_name = RESULT_FILE_NAME,
    decompress = True,
    overwrite = True,  # Set this value true if you want to overwrite the same file.
    timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS # You may optionally cancel the download after a specified time interval.
)

output_status_message("Download result file: {0}".format(result_file_path))

def download_results(request_id, authorization_data):

reporting_download_operation = ReportingDownloadOperation(
    request_id = request_id,
    authorization_data=authorization_data,
    poll_interval_in_milliseconds=1000,
    environment=ENVIRONMENT,
)

reporting_operation_status = reporting_download_operation.track(timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS)

result_file_path = reporting_download_operation.download_result_file(
    result_file_directory = FILE_DIRECTORY,
    result_file_name = RESULT_FILE_NAME,
    decompress = True,
    overwrite = True,  # Set this value true if you want to overwrite the same file.
    timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS # You may optionally cancel the download after a specified time interval.
)

output_status_message("Download result file: {0}".format(result_file_path))
output_status_message("Status: {0}".format(reporting_operation_status.status))

def download_report(reporting_download_parameters):
global reporting_service_manager

report_container = reporting_service_manager.download_report(reporting_download_parameters)

if(report_container == None):
    output_status_message("There is no report data for the submitted report request parameters.")
    sys.exit(0)

report_container.close()

def get_report_request(account_id):
"""
Use a sample report request or build your own.
"""

aggregation = 'Summary'
exclude_column_headers=False
exclude_report_footer=False
exclude_report_header=False
time=reporting_service.factory.create('ReportTime')
# You can either use a custom date range or predefined time.
time.PredefinedTime='LastMonth'
time.ReportTimeZone='PacificTimeUSCanadaTijuana'

time.CustomDateRangeStart = None
time.CustomDateRangeEnd = None
return_only_complete_data=True

account_performance_report_request = get_account_performance_report_request(
    account_id=account_id,
    aggregation=aggregation,
    exclude_column_headers=exclude_column_headers,
    exclude_report_footer=exclude_report_footer,
    exclude_report_header=exclude_report_header,
    report_file_format=REPORT_FILE_FORMAT,
    return_only_complete_data=return_only_complete_data,
    time=time)

return account_performance_report_request

def get_account_performance_report_request(
account_id,
aggregation,
exclude_column_headers,
exclude_report_footer,
exclude_report_header,
report_file_format,
return_only_complete_data,
time):
report_request=reporting_service.factory.create('AccountPerformanceReportRequest')
report_request.Aggregation=aggregation
report_request.ExcludeColumnHeaders=exclude_column_headers
report_request.ExcludeReportFooter=exclude_report_footer
report_request.ExcludeReportHeader=exclude_report_header
report_request.Format=report_file_format
report_request.ReturnOnlyCompleteData=return_only_complete_data
report_request.Time=time
report_request.ReportName = "My Account Performance Report"
scope = reporting_service.factory.create('AccountReportScope')
scope.AccountIds={'long': [account_id] }
report_request.Scope=scope
report_columns=reporting_service.factory.create('ArrayOfAccountPerformanceReportColumn')
report_columns.AccountPerformanceReportColumn.append([
'AccountName',
'CurrencyCode',
'Ctr',
'AverageCpc',
'Conversions',
'Impressions',
'Clicks',
'Spend'
])
report_request.Columns=report_columns

return report_request

if name == 'main':

print("Loading the web service client proxies...")
ENVIRONMENT = 'production'
developerToken = 'xxxxxxxxxxxxxxxxxx'
CustomerId = 1111111111
accountid = 1111111111
from bing.get_access_token import get_access_token

accessToken = get_access_token()

authorization_data=AuthorizationData(
    account_id=accountid,
    customer_id=CustomerId,
    developer_token=developerToken,
    authentication=accessToken,
)

reporting_service_manager=ReportingServiceManager(
    authorization_data=authorization_data,
    poll_interval_in_milliseconds=5000,
    environment=ENVIRONMENT,
)

reporting_service=ServiceClient(
    service='ReportingService',
    version=13,
    authorization_data=authorization_data,
    environment=ENVIRONMENT,
)

authenticate(authorization_data)

main(authorization_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant