php - 使用 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";
}
}
我错过了什么或做错了什么?
解决方案
推荐阅读
- sql - DB2 LUW 9.7 FP5 中的 LISTAGG 函数失败
- .net - 从字典中获取对象
在一个列表中 - javascript - 使用 JavaScript 将 JSON 响应打印为 PDF 或 Excel
- rust - 为什么这个从 C (来自维基百科)移植的希尔伯特曲线实现似乎失败了?
- javascript - 我可以用jQuery“触发”媒体查询吗?
- python-2.7 - 我想替换a.py的实现 用b.py这种方式,怎么写?
- google-apps-script - doPost(e) 如何立即响应 HTTP 200 OK,然后执行长时间功能
- javascript - JavaScript 和对象转换
- sql - 如何替换 SQL 中的字符?
- javascript - FireBase 重复推送