繁体   English   中英

尝试使用Python / Django通过Facebook Marketing API检索Campaign Insight数据时出现FacebookRequestError

[英]FacebookRequestError while trying to retrieve Campaign Insight Data via Facebook Marketing API with Python/Django

我正在尝试使用Python Business SDK通过Facebook的Marketing API获得Campaign Insights,并且得到了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()

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

我们已经解决了这个问题,问题在于wait_for_async_job中的while条件。 只要有至少一个条件为True,就应该有一个“ OR”运算符而不是“ AND”运算符,以便循环进行迭代。 这样,我们检查async_status是否都应为“ Job Completed”,并且完成百分比应为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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM