facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.28k stars 631 forks source link

get_insights_async: AdReportRun to AdsInsights #545

Closed JayXu1988 closed 5 years ago

JayXu1988 commented 5 years ago

get_insights_async raises many warnings about FIELD, because of the differences between fields of AdReportRun and AdsInsights.

facebook-github-bot commented 5 years ago

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

facebook-github-bot commented 5 years ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

jingping2015 commented 5 years ago

I think you should call like this

async_job = AdAccount(account_id).get_insights_async(
    [],  // you should not set fields here directly 
    params,
)

async_job.api_get()
while async_job[AdReportRun.Field.async_percent_completion] < 100:
    time.sleep(1)
    async_job.api_get()

print(async_job.get_result(fields))

You can check more details here https://developers.prod.facebook.com/docs/marketing-api/insights/best-practices/

mdmoo1978 commented 5 years ago

Based on my use of 3.3.2, that isn't how it works in real life. In order to make it work, you must include fields in the params of the async call. Otherwise, not all fields are produce by the API.

In fact, this is not the only thing that doesn't work as described. Just in the code you copied there, the while loop is not correct. You must do something more like:

while async_job[AdReportRun.Field.async_percent_completion] < 100 and Field.async_status]!='Job Completed':

The link you referenced is great in concept, but actually doing them is much harder than just go to the link and it will solve all your problems.