How to used aweber api to add new subscriber usign php and aweber OAuth 2.0 Examples


i am used aweber api in add subscriber and OAuth 2.0 Examples usign php

$body = [
  'ad_tracking' => 'ebook',
  'custom_fields' => [
    'apple' => 'fuji',
    'pear' => 'bosc'
  'email' => '[email protected]',
  'ip_address' => '',
  'last_followup_message_number_sent' => 0,
  'misc_notes' => 'string',
  'name' => 'Anand',
  'strict_custom_fields' => 'true',
  'tags' => [
$headers = [
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'User-Agent' => 'AWeber-PHP-code-sample/1.0'
$url = "{$accountId}/lists/{$listId}/subscribers";
$response = $client->post($url, ['json' => $body, 'headers' => $headers]);
echo $response->getHeader('Location')[0];

Error Code :

Notice: Undefined variable: client in D:\xampp\htdocs\Aweber\index.php on line 30

Fatal error: Uncaught Error: Call to a member function post() on null in D:\xampp\htdocs\Aweber\index.php:30 Stack trace: #0 {main} thrown in D:\xampp\htdocs\Aweber\index.php on line 30




The AWeber examples make use of a third party HTTP client for PHP called Guzzle. You need to set up the client first before you'll be able to use it. You can see an example of this in the code examples on AWeber's GitHub here:

Note the call to create the client:

// Create a Guzzle client
$client = new GuzzleHttp\Client();

Documentation for Guzzle can be found here:

It also looks like you're missing the authorization header. When you make the API call it will fail unless you include your access token in the header, so don't forget that part! You can add it to your existing headers like so:

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

Where $accessToken is a variable you initialize with your token somewhere.

People are also looking for solutions to the problem: php - Should I use truthy approach rather than is_null, isset, or empty?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.