0

我正在尝试使用 Python Business SDK 通过 Facebook 的营销 API 获取营销活动洞察,但我收到了 FacebookRequestError:

  Message: Call was not successful
  Method:  GET
  Path:    https://graph.facebook.com/v3.1/2603111949730990/insights
  Params:  {}

  Status:  400
  Response:
    {
      "error": {
        "message": "Error accessing adreport job.",
        "type": "OAuthException",
        "code": 2601,
        "error_subcode": 1815107,
        "is_transient": true,
        "error_user_title": "Loading Async Ads Report Failed",
        "error_user_msg": "Sorry, the report cannot be loaded successfully. Please check if your job status is completed instead of failed or running before fetching the data.",
        "fbtrace_id": "BQJsdi3g5tX"
      }
    }

我已经尝试通过检查作业状态是否不是“作业完成”以及作业完成百分比是否小于 100 来修改 wait_for_async_job() 函数的代码,但问题仍然存在。

def wait_for_async_job(async_job):
    async_job.remote_read()
    while async_job[AdReportRun.Field.async_status] != 'Job Completed' and async_job[AdReportRun.Field.async_percent_completion] < 100:
        time.sleep(1)
        async_job.remote_read()

任何帮助将非常感激。先感谢您!

4

1 回答 1

4

我们已经解决了这个问题,问题在于 wait_for_async_job 中的 while 条件。应该有一个“OR”运算符而不是“AND”,这样只要至少有一个条件为真,循环就会迭代。这样,我们检查 async_status 是否应该是“作业完成”并且完成百分比应该是 100。我将答案留在这里,以防有人觉得它有帮助。

def wait_for_async_job(async_job):
    async_job.remote_read()
    while async_job[AdReportRun.Field.async_status] != 'Job Completed' or async_job[AdReportRun.Field.async_percent_completion] < 100:
        time.sleep(1)
        async_job.remote_read()
于 2019-02-19T15:52:28.190 回答