【发布时间】:2021-10-26 21:30:31
【问题描述】:
我正在使用this package As SDK。所以基本上我想要实现的是将用户添加到列表中,但具有同意状态或电子邮件和短信,我从我自己的问题的一个答案中找到的是这段代码。所以我尝试了它,但它又遇到了另一个错误。
TypeError
Cannot access offset of type string on string
代码来自@Ohgodwhy 的answer.
public function chnages()
{
$client = new Klaviyo('Your_Private_apikey', 'Public_Api_key');
$customer_properties = [
'$email' => "someone@mailinator9.com",
'$first_name' => "Thomas9",
'$last_name' => "Jefferson",
'phone_number' => "1234567890"
];
$consents = [];
if (request()->get('sms_consent', false)) {
$consents['sms_consent'] = true;
}
if (request()->get('email_consent', false)) {
$consents['email_consent'] = true;
}
foreach ($consents as $type => $consented) {
if ($consented) {
$consents['$consent'] = array_merge(
data_get($consents, '$consent', []),
[explode('_', $type)[0]] //e.g. sms, email
);
}
}
$client->lists->addSubscribersToList('LIST_ID', array_merge($customer_properties, $consents));
}
【问题讨论】:
标签: php arrays laravel string api