1. Go to this page and download the library: Download weebly/cloud-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
weebly / cloud-client example snippets
// Get the admin account
try {
$account = new WeeblyCloud\Account();
} catch (WeeblyCloud\Utils\CloudException $e) {
print("Unable to get account.\n");
print("Error code {$e->getCode()}: {$e->getMessage()}.\n");
exit();
}
//Create a new user
try {
$user = $account->createUser("[email protected]");
} catch (WeeblyCloud\Utils\CloudException $e) {
print("Unable to create user.\n");
print("Error code {$e->getCode()}: {$e->getMessage()}.\n");
exit();
}
//Store the user's ID
$user_id = $user->getProperty("user_id");
//Create a site
try {
$site = $user->createSite("domain.com", ["site_title"=>"My Website"]);
} catch (WeeblyCloud\Utils\CloudException $e) {
print("Unable to create site.\n");
print("Error code {$e->getCode()}: {$e->getMessage()}.\n");
exit();
}
//Store the site's ID
$site_id = $site->getProperty("site_id");
//Get and print a login link
try {
print($site->loginLink());
} catch (WeeblyCloud\Utils\CloudException $e) {
print("Unable to generate login link.\n");
print("Error code {$e->getCode()}: {$e->getMessage()}.\n");
exit();
}
$pages = $site->listPages(["query"=>"help"]);
while ($page = $pages->next()) {
print($page->getProperty("title")."\n");
}
foreach ($site->listPages(["query"=>"help"]) as $page) {
print($page->getProperty("title")."\n");
}
# Get client
$client = WeeblyCloud\Utils\CloudClient::getClient();
# Request the /account endpoint
$client->get("account");
# Get client
$client = WeeblyCloud\Utils\CloudClient::getClient();
# Build endpoint with IDs
$endpoint = "user/{$user_id}/site/{$site_id}/page/{$page_id}";
# Make the request
$client->patch($endpoint, ["title"=>"New Title"]);
# Get client
$client = WeeblyCloud\Utils\CloudClient::getClient();
# Build endpoint with IDs
$endpoint = "user/{$user_id}/site";
# Make the request (get all sites this user owns)
$client->get($endpoint, ["role"=>"owner"]);
# Make a request
$response = $client->get("account");
# Print JSON body of response
print($response->body);