Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accountfacebook.php
1<?php
2
4
8
10{
11 public const TYPE_CODE = LeadAds\Service::TYPE_FACEBOOK;
12
13 public const URL_ACCOUNT_LIST = 'https://www.facebook.com/bookmarks/pages';
14
15 public const URL_INFO = 'https://www.facebook.com/business/a/lead-ads';
16
17 protected static $listRowMap = array(
18 'ID' => 'ID',
19 'NAME' => 'NAME',
20 );
21
25 public function getList()
26 {
27 $paginator = new Paginator(
28 $this->getRequest(),
29 [
30 'methodName' => 'leadads.accounts.get',
31 'parameters' => [
32 'fields' => ['id','name','category','access_token','tasks'],
33 "params" => [
34 "limit" => 50
35 ]
36 ],
37 ]
38 );
39
40 $result = null;
41 $data = [];
42
43 foreach ($paginator as $request)
44 {
45 if (!$request->isSuccess())
46 {
47 return $request;
48 }
49
50 foreach ($request->getData() as $item)
51 {
52 if (array_intersect($item['tasks'] ?? [], ['MODERATE', 'CREATE_CONTENT', 'MANAGE']))
53 {
54 $data[] = $item;
55 }
56 }
57 $result = $request;
58 }
59
60 !$result?:$result->setData($data);
61
62 return $result;
63 }
64
69 public function getProfile(): ?array
70 {
71 $response = $this->getRequest()->send([
72 'methodName' => 'leadads.profile.get',
73 'parameters' => [
74 'fields' => ['id','name','picture','link']
75 ]
76 ]);
77
78 if ($response->isSuccess() && $data = $response->fetch())
79 {
80
81 return [
82 'ID' => $data['ID'],
83 'NAME' => $data['NAME'],
84 'LINK' => $data['LINK'],
85 'PICTURE' => $data['PICTURE'] ? $data['PICTURE']['data']['url'] : null,
86 ];
87 }
88
89 return null;
90 }
91}