Then import Client and call initialize to initialize it:
use \LeanCloud\Client;
// Provide App ID, App Key, and Master Key as parameters
Client::initialize("{{appid}}", "{{appkey}}", "{{masterkey}}");
Client::setServerUrl("{{domain}}");
Enabling Debug Logs
You can easily trace the problems in your project by turning debug logs on during the development phase. Once enabled, details of every request made by the SDK along with errors will be output to IDE, browser console, or your app's Dashboard > LeanEngine > App logs.
// Place the line after Client::initialize(); only needs to be called once
Client::setDebug(true);
Make sure debug logs are turned off before your app is published. Failure to do so may lead to the exposure of sensitive data.
Verifying
First of all, make sure you are able to connect to LeanCloud server. You can test it by running the following command:
curl "https://{{domain}}/1.1/date"
If everything goes well, it will return the current date:
This guide is written for the latest version of our SDK. If you encounter any error, please first make sure you have the latest version installed.
401 Unauthorized
If you get a 401 error or see the following content in network logs:
{
"code": 401,
"error": "Unauthorized."
}
It means that the App ID or App Key might be incorrect or don't match. If you have multiple apps, you might have used the App ID of one app with the App Key of another one, which will lead to such error.
Client Cannot Access the Internet
Make sure you have granted enough permissions for your mobile app.
How to Install the PHP SDK
Installing SDK
There are several ways for you to install our SDK and the most convenient one is to use a package manager.
Installing with Package Manager
composer
The easiest way to integrate our SDK into your project is to use composer. Run the following command to install it:
Keep in mind that
leancloud-sdk
depends on thecurl
extension (you may need to installphp-curl
if you are using Linux).Installing Manually
Download SDK
Initializing Your Project
To begin with, get your App ID and App Key from your app's Dashboard > Settings > App Keys.
Then import
Client
and callinitialize
to initialize it:Enabling Debug Logs
You can easily trace the problems in your project by turning debug logs on during the development phase. Once enabled, details of every request made by the SDK along with errors will be output to IDE, browser console, or your app's Dashboard > LeanEngine > App logs.
Make sure debug logs are turned off before your app is published. Failure to do so may lead to the exposure of sensitive data.
Verifying
First of all, make sure you are able to connect to LeanCloud server. You can test it by running the following command:
If everything goes well, it will return the current date:
Then add the following code into your project:
Save the file and run it.
Then go to your app's Dashboard > LeanStorage > Data >
TestObject
. If you see the following content, it means that you have correctly installed the SDK.See Debugging if you're not seeing the content.
Debugging
This guide is written for the latest version of our SDK. If you encounter any error, please first make sure you have the latest version installed.
401 Unauthorized
If you get a
401
error or see the following content in network logs:It means that the App ID or App Key might be incorrect or don't match. If you have multiple apps, you might have used the App ID of one app with the App Key of another one, which will lead to such error.
Client Cannot Access the Internet
Make sure you have granted enough permissions for your mobile app.