2017-04-18 9 views
0

完全なコードを作成することを約束します。使用はがつがつ食うとmailchimpリストに

私は私が得たphp create_list_memeber_update.php

エラーを実行しています:

PHP Fatal error: Uncaught InvalidArgumentException: Invalid resource type: array in /var/www/html/test/testme/test_guzzle/vendor/guzzlehttp/psr7/src/functions.php:116 
Stack trace: 
#0 /var/www/html/test/testme/test_guzzle/vendor/guzzlehttp/psr7/src/Request.php(53): GuzzleHttp\Psr7\stream_for(Array) 
#1 /var/www/html/test/testme/test_guzzle/create_list_memeber_update.php(49): GuzzleHttp\Psr7\Request->__construct('POST', Object(GuzzleHttp\Psr7\Uri), Array, Array) 
#2 {main} 
    thrown in /var/www/html/test/testme/test_guzzle/vendor/guzzlehttp/psr7/src/functions.php on line 116 

私は

$headers = array(
    'User-Agent' => 'testing/1.0', 
    'Accept'  => 'application/json' 
); 

コードcreate_list_memeber_update.phpのヘッダーに何かあると思う:

<?php 

// auto load 
require 'vendor/autoload.php'; 

use GuzzleHttp\Psr7\Request; 

// opt 
$option = array(
    'base_uri' => "https://us12.api.mailchimp.com/3.0/", 
    'auth' => ['apikey', '292bae37c631ac3ba03ed0640b44e6c3'], 
); 

// client 
$client = new \GuzzleHttp\Client($option); 

// data for a new list 
$data = array(
    "name" => "test_mailchimp", 
    "contact" => array(
    "company" => "MailChimp", 
    "address1" => "675 Ponce De Leon Ave NE", 
    "address2" => "Suite 5000", 
    "city" => "Atlanta", 
    "state" => "GA", 
    "zip" => "30308", 
    "country" => "US", 
    "phone" => "12345678", 
), 
    "permission_reminder" => "You're receiving this email because you signed up for updates.", 
    "use_archive_bar" => true, 
    "campaign_defaults" => array(
    "from_name" => "test", 
    "from_email" => "[email protected]", 
    "subject" => "test_subject", 
    "language" => "en", 
), 
    "notify_on_subscribe" => "", 
    "notify_on_unsubscribe" => "", 
    "email_type_option" => true, 
    "visibility" => "pub", 
); 

$headers = array(
    'User-Agent' => 'testing/1.0', 
    'Accept'  => 'application/json' 
); 
$body = ['json' => $data]; 
$req_create_list = new Request('POST', 'lists', $headers, $body); 

// promise 
$promise = $client 
    ->sendAsync($req_create_list) 
    ->then(function ($res) { 
    echo $res->getBody(); 
    }); 
$promise->wait(); 
+1

完全に正常に動作し 'リソースまたはオブジェクトのいずれかを期待されているstream_for'。 – RobFos

答えて

0

これは私が見つけた解決策があり、そのあなたが関数に配列を渡している

// format for mail chimp data 


    --url 'https://usX.api.mailchimp.com/3.0/batches' \ 
    --user 'anystring:apikey' \ 
    --header 'content-type: application/json' \ 
    --data '{"operations" : [{"method" : "POST","path" : 
    "lists/624ea08019/members", "body": " 
    {\"email_address\":\"[email protected]\", 
    \"status\":\"subscribed\"}"}, 
    //end format 

    $userlist = array(format array data)  
    $auth = base64_encode('user:'.config('mailchimp.api_key')); 
    //API URL 
    $urll = "https://".config('mailchimp.data_center').".api.mailchimp.com/3.0/batches"; 
    //API authentication Header 
    $headers = array(
     'Accept'  => 'application/json', 
     'Authorization' => 'Basic '.$auth 
    ); 
    $client = new Client(); 
    $req_Memeber = new Request('POST', $urll, $headers, $userlist); 
    // promise 
    $promise = $client->sendAsync($req_Memeber)->then(function ($res){ 
      echo "Synched"; 
     }); 
     $promise->wait(); 
関連する問題