简体   繁体   English

从 facebook API 获取所有潜在客户广告

[英]Get all lead ads form facebook API

I am trying to get all lead generation forms in my PHP script using Facebook API version 9.0我正在尝试使用 Facebook ZDB974238714CA8DE634A7CE1DF083 版本在我的 PHP 脚本中获取所有潜在客户生成 forms

I am making the request like this:我提出这样的要求:

https://graph.facebook.com/v9.0/<PAGE_ID>/leadgen_forms?<access_token>

But its returning error, saying但它的返回错误,说

{
   "error": {
      "message": "(#12) leadgen_forms field is deprecated for versions v5.0 and higher",
      "type": "OAuthException",
      "code": 12,
      "fbtrace_id": "ARMp3WCko2raN5521458h"
   }
}

If I change the version in the above request, it says:如果我在上述请求中更改版本,它会说:

You are calling a deprecated version of the Ads API.您正在调用已弃用的广告 API 版本。 Please update to the latest version: v9.0.请更新到最新版本:v9.0。

UPDATE:更新:

Here's the SDK function which i am using to get Lead Generation Forms:这是 SDK function,我用来获取潜在客户生成 Forms:

public function getLeadGenForms(array $fields = array('first_name', 'last_name'), array $params = array(), $pending = false) {
    $this->assureId();

    $param_types = array(
      'query' => 'string',
    );
    $enums = array(
    );

    $request = new ApiRequest(
      $this->api,
      $this->data['id'],
      RequestInterface::METHOD_GET,
      '/leadgen_forms',
      new LeadgenForm(),
      'EDGE',
      LeadgenForm::getFieldsEnum()->getValues(),
      new TypeChecker($param_types, $enums)
    );
    $request->addParams($params);
    $request->addFields($fields);
    return $pending ? $request : $request->execute();
  }

This is the correct GET request URL:这是正确的 GET 请求 URL:

https://graph.facebook.com/v9.0/<PAGE_ID>/leadgen_forms?access_token=<page_access_token>

And example use of the FB PHP SDK:以及使用 FB PHP SDK 的示例:

try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/<PAGE_ID>/leadgen_forms',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

Source: Generated from the Graph API Explorer .来源:从图 API Explorer生成。

Screenshot of a working error-free response:工作无错误响应的屏幕截图: 在此处输入图像描述

Requirements:要求:

  • Use the page access token of the page <PAGE_ID> (not your own user token or any other page).使用页面<PAGE_ID>页面访问令牌(不是您自己的用户令牌或任何其他页面)。
  • Grant the pages_show_list , pages_read_engagement and pages_manage_ads permissions to the FB app that you connect to (to get the page access token).pages_show_listpages_read_engagementpages_manage_ads权限授予您连接到的 FB 应用程序(以获取页面访问令牌)。

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

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