elvanto/api-php

该软件包已被废弃,不再维护。未建议替代软件包。

Elvanto教会管理软件的API PHP库。

1.0.7 2019-09-03 22:48 UTC

This package is auto-updated.

Last update: 2023-11-04 07:47:35 UTC


README

此库已准备好与Elvanto API的版本1一起使用。Elvanto API

认证

Elvanto API支持使用OAuth 2API密钥进行认证。

这是为什么?

  • 简要总结:这是一个API包装器,可与Elvanto帐户一起使用。此包装器可供开发人员为其自己的教会开发程序,或设计使用OAuth认证与其他教会共享的集成。
  • 版本1.0

使用OAuth 2

此库提供功能,帮助您获取访问令牌和刷新令牌。您的应用程序应该做的第一件事是将用户重定向到Elvanto授权URL,在那里他们将有机会批准您的应用程序访问其Elvanto帐户。您可以通过使用authorize_url()方法获取此授权URL,如下所示

require_once('Elvanto_API.php');

$elvanto = new Elvanto_API();

$authorize_url = $elvanto->authorize_url(
	'Client ID for your application',
  'Redirect URI for your application',
  'The permission level your application requires',
  'Optional state data to be included'
);
// Redirect your users to $authorize_url.

如果用户批准您的应用程序,他们将被重定向到您指定的redirect_uri,该URL将包括一个code参数,并可选地包含一个在查询字符串中的state参数。您的应用程序应该实现一个处理器,可以交换传递给它的代码以获取访问令牌,如下所示使用exchange_token()

require_once('Elvanto_API.php');

$elvanto = new Elvanto_API();

$result = $elvanto->exchange_token(
  'Client ID for your application',
  'Client Secret for your application',
  'Redirect URI for your application',
  'A unique code for your user' // Get the code parameter from the query string.
);

$access_token = $result->access_token;
$expires_in = $result->expires_in;
$refresh_token = $result->refresh_token;
// Save $access_token, $expires_in and $refresh_token.

此时,您已为您的用户获得了访问令牌和刷新令牌,您应将其存储在方便的位置,以便您的应用程序可以在您的用户想要进行未来的Elvanto API调用时查找这些值。

一旦您为您的用户获得了访问令牌和刷新令牌,您就可以进行认证并进一步进行API调用,如下所示

require_once('Elvanto_API.php');

$auth_details = array(
	'access_token' => 'your access token',
	'refresh_token' => 'your refresh token'
);
$elvanto = new Elvanto_API($auth_details);

$results = $elvanto->call('people/getAll');
var_dump($results);

所有OAuth令牌都有过期时间,可以使用相应的刷新令牌进行更新。如果尝试进行API调用时访问令牌过期,您将收到错误响应,因此您的代码应处理此情况。以下是一个示例,说明您可以如何这样做

require_once('Elvanto_API.php');

$auth_details = array(
	'access_token' => 'your access token',
	'refresh_token' => 'your refresh token'
);
$elvanto = new Elvanto_API($auth_details);

$results = $elvanto->call('people/getAll');
if (isset($results->error)) {
	// If you receive '121: Expired OAuth Token', refresh the access token.
	if ($results->error->code == 121) {
		list($new_access_token, $new_expires_in, $new_refresh_token) =
		  $elvanto->refresh_token();
		// Save $new_access_token, $new_expires_in, and $new_refresh_token.
	}
	// Make the call again.
	$results = $elvanto->call('people/getAll');
}
var_dump($results);

使用API密钥

require_once('Elvanto_API.php');

$auth_details = array('api_key' => 'your API Key');
$elvanto = new Elvanto_API($auth_details);

$results = $elvanto->call('people/getAll');
var_dump($results);

要在调用中发送参数,请在端点之后添加一个包含您参数的数组。

例如,要编辑现有成员的电子邮件地址

$results = $elvanto->('people/edit', array('id'=>'XXXXXXX', 'fields'=>array('email'=>'new_email@address.com')));

文档

文档可以在Elvanto API网站上找到。

更新

关注我们的Twitter,以了解API的变化。

支持

有关API PHP包装器的错误,请使用问题跟踪器

有关API本身的建议,请在论坛中发帖或通过我们的网站联系我们