首页 > 解决方案 > 使用 PHP 进行 Aweber 集成

问题描述

我正在尝试创建自动登录。我不希望我的客户为此使用凭据登录。我正在使用这个库 https://github.com/aweber/public-api-examples/tree/master/php

像这样创建了一个 credentials.ini 文件

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

当我尝试访问 index.php 文件时,它会显示这样的错误。错误

//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";
    }
}

我错过了什么或做错了什么?

标签: phpaweber

解决方案


推荐阅读