Aweber integration using PHP

357 views Asked by At

I am trying to create an auto-login. I don't want my client to login with credentials for this. I am using this library https://github.com/aweber/public-api-examples/tree/master/php

Created a credentials.ini file like this

clientId = 'xxx'
clientSecret = 'xxx'
accessToken = 'https://auth.aweber.com/oauth2/token'
redirect_uri = 'http://localhost:8080/php-aweber/'

when I try to access the index.php file, It shows an error like this.Error

//index.php

<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;

const BASE_URL = 'https://api.aweber.com/1.0/';

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

// Load credentials
$credentials = parse_ini_file('credentials.ini');
$accessToken = $credentials['accessToken'];

/**
 * Get all of the entries for a collection
 *
 * @param Client $client HTTP Client used to make a GET request
 * @param string $accessToken Access token to pass in as an authorization header
 * @param string $url Full URL to make the request
 * @return array Every entry in the collection
 */
function getCollection($client, $accessToken, $url) {
    $collection = array();
    while (isset($url)) {
        $request = $client->get($url,
            ['headers' => ['Authorization' => 'Bearer ' . $accessToken]]
        );
        $body = $request->getBody();
        $page = json_decode($body, true);
        $collection = array_merge($page['entries'], $collection);
        $url = isset($page['next_collection_link']) ? $page['next_collection_link'] : null;
    }
    return $collection;
}

// get all of the accounts
$accounts = getCollection($client, $accessToken, BASE_URL . 'accounts');

// get all sharing integration uri's for twitter and facebook
// these are used to create a broadcast that will post to twitter or facebook
// see broadcast example here: https://github.com/aweber/public-api-examples/blob/master/php/create-schedule-broadcast
$integrations = getCollection($client, $accessToken, $accounts[0]['integrations_collection_link']);
echo("Integrations:\n");
foreach ($integrations as $integration) {
    if (in_array(strtolower($integration['service_name']), ['twitter', 'facebook'], true)) {
        echo "{$integration['service_name']} {$integration['login']} {$integration['self_link']}\n";
    }
}

What am I missing or doing wrong?

0

There are 0 answers