我正在尝试从基于apikey的mailchimp获取列表,该列表存储在针对user_id的数据库中。我正在获取所有基于apikey的列表,这些列表存储在laravel的配置文件中。但是在这里我想根据存储在数据库中的api密钥从mailchimp获取列表。
我用来从配置文件中获取基于apikey的所有列表的代码是:
public function getLists(Request $request)
{
$request->user()->id;
$result = MailchimpFacade::request( 'lists', ['fields' => 'lists.id,lists.name'] );
$resultArray = ['status' => 1, 'message' => 'Lists appear successfully!', 'dataArray' => $result];
return \Illuminate\Support\Facades\Response::json($resultArray, 200);
}
这里我想根据存储在数据库中的apikey从mailchimp获取列表。 您的时间和帮助将受到高度赞赏!
public function getLists (Request $request)
{
$request->user()->id;
$mc = new MailChimp($request->input('api_key'));
$result = $mc->get('/ping');
return \Illuminate\Support\Facades\Response::json($result, 200);
}
<?php
namespace App\Http\Controllers;
use App\APIKEY;
use DrewM\MailChimp\MailChimp;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Validator;
class ApiController extends Controller
{
public function getLists (Request $request)
{
$request->user()->id;
$mc = new MailChimp($request->input('api_key'));
$result = $mc->get('/ping');
return \Illuminate\Support\Facades\Response::json($result, 200);
}
}
public function getLists(Request $request)
{
Auth::user()->id;
$apikey = $request->input('api_key');
DB::table('apikey')
->where('api_key','=', $apikey)
->get();
if($apikey){
$mc = new MailChimp($apikey);
$mailchimp_ping = $mc->get('lists',['fields' => 'lists.id,lists.name'] );
return \Illuminate\Support\Facades\Response::json($mailchimp_ping, 200);
}
else
{ $errorResponse = [
'message' => 'Lists not found!',
'error' => '401'
];
return Response::json( $errorResponse);
}
}
答案 0 :(得分:0)
使用Refused to display 'https://myshop.myshopify.com/admin/apps/myappname' in a frame because it set 'X-Frame-Options' to 'deny'.
代替DrewM\MailChimp\MailChimp
。
Facade
完全控制器,根据您的需要进行编辑 -
use DrewM\MailChimp\MailChimp;
$mc = new MailChimp($apikey);
$result = $mc->get('lists');
print_r($result);
有关详细信息,请参阅this。