Skip to content
fkmhrk edited this page Sep 18, 2013 · 4 revisions

Use cases

Get current user's info

Access token will be given.

require_once (dirname(__FILE__). '/libs/kiilib/src/kii/KiiAppAPI.php');

$context = new KiiContext(APP_ID, APP_KEY, SITE);
$context->setAccessToken($accessToken);

$appApi = new KiiAppAPI($context);
$userApi = $appApi->userAPI();

try {
	$user = $userApi->getUser(new KiiUser('me'));
} catch (CloudException $e) {
	//error handling
}

Find user by email and send push message to him/her.

EmailAddress will be given.

require_once (dirname(__FILE__). '/libs/kiilib/src/kii/KiiAppAPI.php');

$context = new KiiContext(APP_ID, APP_KEY, SITE);
$api = new KiiAppAPI($context);
$userApi = $api->userAPI();
$topicApi = $appApi->topicAPI();

# login as App Admin
try {
	$api->loginAsAdmin($clientId, $clientSecret);
} catch (CloudException $e) {
	// error handling
	return;
}

# find user
$user = null;
try {
	$user = $userApi->findByEmail($emailAddress);
} catch (CloudException $e) {
	// error handling
	return;
}

# send Topic message
$topicName = 'inbox';
$topic = new KiiTopic($user, $topicName);
$message = new KiiTopicMessage();
$message->data['msg'] = 'hello';

try {
	$topicApi->sendMessage($topic, $message);
} catch (CloudException $e) {
	//error handling
}
Clone this wiki locally