如何在mailchimp中仅获取字段(列)
Posted
技术标签:
【中文标题】如何在mailchimp中仅获取字段(列)【英文标题】:How to get only field(column) in mailchimp 【发布时间】:2018-08-12 17:33:51 【问题描述】:我正在获取带有值的字段名称,但我只想在 mailchimp 中获取字段名称:
我的控制器代码:
public function getFieldsListMailchimp(Request $request)
$list_id = $request->input('list_id');
$user_id = $request->user()->id;
$apikey = DB::table('user_mlc_mailchimp')->where('user_id', '=', $user_id)->value('api_key');
if ($list_id)
$mc = new MailChimp($apikey);
$fields = $mc->get('/lists/'.$list_id.'/members?fields=members.id,members.email_address,members.merge_fields');
$fields = ['status' => 1, 'message' => 'Fields list!', 'dataArray' => $fields];
return Response::json($fields, 200);
else
$errorResponse = [
'message' => 'Lists not found!',
'error' => '401'
];
return Response::json($errorResponse);
我得到这段代码的输出是:
"status": 1,
"message": "Fields list!",
"dataArray":
"members": [
"id": "663657d6bee76fdd3285c879bf2849e2",
"email_address": "shahzad.hussain@vaivaltech.com",
"merge_fields":
"FNAME": "shahzad",
"LNAME": "Hussain"
,
"id": "b59a741183b7e1990156a46faa29b60c",
"email_address": "Hello@gmail.com",
"merge_fields":
"FNAME": "Shahzad",
"LNAME": "Hussain"
]
如您所见,我只想获取字段名称(id、email_address、merge_fields(FNAME、LNAME)但在这里我获取字段名称以及值我只想在这里获取字段名称? 任何帮助将不胜感激! 提前致谢。
public function getFieldsListMailchimp(Request $request)
$list_id = $request->input('list_id');
$user_id = $request->user()->id;
$apikey = DB::table('user_mlc_mailchimp')->where('user_id', '=', $user_id)->value('api_key');
if ($list_id)
$mc = new MailChimp($apikey);
$fields = $mc->get('/lists/'.$list_id.'/members?fields=members.id,members.email_address,members.merge_fields');
$fields = ['status' => 1, 'message' => 'Fields list!', 'dataArray' => array_keys($fields)];
return Response::json($fields, 200);
else
$errorResponse = [
'message' => 'Lists not found!',
'error' => '401'
];
return Response::json($errorResponse);
【问题讨论】:
【参考方案1】: $fields = [
'status' => 1,
'message' => 'Fields list!',
'dataArray' => array_keys($fields)
]);
return Response::json($fields, 200);
Array Keys, 只会给你钥匙
【讨论】:
当我添加 array_keys 时,它只显示一条消息: "status": 1, "message": "Fields list!", "dataArray": [ "members" ] 它没有显示任何字段名称,请您进一步指导我 我发布了我的整个控制器代码以及您的答案,请参阅。 它应该只显示键,但我不知道为什么它不显示 这个问题还有什么其他的吗?以上是关于如何在mailchimp中仅获取字段(列)的主要内容,如果未能解决你的问题,请参考以下文章
如何在类中声明const并获取针对mailchimp列表的字段名称