weebly / weebly_client

适用于 Weebly 平台 API 的 PHP 客户端

1.1.0 2017-08-24 21:17 UTC

README

Weebly 客户端是一个基本的 PHP 类,简化了与 Weebly REST API 的交互。

您可以在 https://dev.weebly.com/get-started-with-developing-apps.html 查找有关如何设置您的 Weebly 项目的更多详细信息。

您可以在 https://dev.weebly.com/about-rest-apis.html 查找有关您可以使用 Weebly 客户端访问的各种端点的详细信息。

用法

创建客户端实例

您可以这样创建一个新的 Weebly 客户端:

$client = new \Weebly\WeeblyClient($client_id, $client_secret, $user_id, $site_id, $access_token);

您必须向构造函数提供的唯一必填选项是 $client_id$client_secret。一旦您在 Weebly 上注册了开发者账户,您可以在您的开发者仪表板上找到这两个值 https://www.weebly.com/developer-admin。请将这些凭证安全地存储在您的服务器上,不要公开暴露。当用户通过 App OAuth 流程授予您的应用程序权限时,$user_idsite_id$access_token 将对您可用。除非您正在访问 OAuth 方法,否则您不需要提供这些参数。(例如:存储 API站点 API

您可以在 https://dev.weebly.com/authentication-with-oauth2.html 查找有关 OAuth 流的更多信息。

通过 OAuth 流进行授权

WeeblyClient 提供了一些辅助方法来帮助您完成 OAuth 流程。* getAuthorizationUrl 返回一个正确格式化的授权 URL,您应该在我们的服务器启动 OAuth 流后对其进行响应。* getAccessToken 在您获得 OAuth 中必要的授权代码后检索访问令牌。

您可以在 https://dev.weebly.com/configure-oauth.html 查找有关如何配置 OAuth 流以及如何获取 $user_idsite_id$access_token 的详细信息。

进行 API 调用

我们提供了简化函数,用于使用 GET、POST、DELETE、PATCH 和 PUT 方法进行请求。

示例

获取站点详情

$endpoint = '/user/sites/' . $site_id;
$response = $client->get($endpoint);

标记产品为已发货

$endpoint = '/user/sites/' . $site_id . '/store/orders/' . $order_id . '/shipments/' . $order_shipment_id;
$product = ['tracking_number' => '1234567810abcde']; //Modifying the tracking_number on an unshipped product will mark it as shipped as well!
$response = $client->put($endpoint, $product);

您可以在 https://dev.weebly.com/about-rest-apis.html 查找有关您可以使用 Weebly 客户端访问的各种端点的详细信息。

有问题?

如果您对 Weebly 客户端有任何问题或功能请求,请创建一个新的问题。对于一般的 API 问题,请联系我们 dev-support@weebly.com,我们将很乐意提供帮助!