如何使用aweberapi添加新订户usign php和aweber OAuth 2.0示例

如何使用aweberapi添加新订户usign php和aweber OAuth 2.0示例,php,aweber,Php,Aweber,我使用php在AddSubscriber和OAuth2.0示例中使用了AWeberAPI require_once('aweber_api/aweber_api.php'); $body = [ 'ad_tracking' => 'ebook', 'custom_fields' => [ 'apple' => 'fuji', 'pear' => 'bosc' ], 'email' => 'anand@gmail.com', 'ip

我使用php在AddSubscriber和OAuth2.0示例中使用了AWeberAPI

require_once('aweber_api/aweber_api.php');
$body = [
  'ad_tracking' => 'ebook',
  'custom_fields' => [
    'apple' => 'fuji',
    'pear' => 'bosc'
  ],
  'email' => 'anand@gmail.com',
  'ip_address' => '192.168.1.1',
  'last_followup_message_number_sent' => 0,
  'misc_notes' => 'string',
  'name' => 'Anand',
  'strict_custom_fields' => 'true',
  'tags' => [
    'slow',
    'fast',
    'lightspeed'
  ]
];
$headers = [
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'User-Agent' => 'AWeber-PHP-code-sample/1.0'
];
$listId='myid';
$accountId='myid';
$url = "https://api.aweber.com/1.0/accounts/{$accountId}/lists/{$listId}/subscribers";
$response = $client->post($url, ['json' => $body, 'headers' => $headers]);
echo $response->getHeader('Location')[0];
错误代码:

注意:第30行的D:\xampp\htdocs\Aweber\index.php中的未定义变量:client


致命错误:未捕获错误:在第30行的D:\xampp\htdocs\Aweber\index.php:30堆栈跟踪:#0{main}中抛出了一个空的成员函数post()。Aweber示例使用了一个名为Guzzle的第三方HTTP php客户端。您需要先设置客户端,然后才能使用它。您可以在AWeber的GitHub上的代码示例中看到这样的示例:

请注意创建客户端的调用:

// Create a Guzzle client
$client = new GuzzleHttp\Client();
Guzzle的文档可在此处找到:

看起来您还缺少授权标头。当您进行API调用时,它将失败,除非您在头中包含您的访问令牌,所以不要忘记这一部分!您可以将其添加到现有标题中,如下所示:

$headers = [
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'User-Agent' => 'AWeber-PHP-code-sample/1.0',
    'Authorization' => 'Bearer ' . $accessToken
];

其中$accessToken是您在某处使用令牌初始化的变量。

您认为
$client
是在哪里定义的?可能重复的不工作,这是get post方法….
$client
根本没有在您的代码中定义。。。这就是我们所能说的