we have a simple sample code as realtime
client in mgp-instagram
private api
into examples
directory which named realtimeClient.php
after running this file from command line that wait receiving on some rtc
commands such as
live-started
, thread-created
and after that when i get new thread from anyone or when our threads updated with new messages, i don’t get any result and output in terminal
can anybody help me how can i get this actions? receiving new messages or updating threads
<?php
set_time_limit(0);
date_default_timezone_set('UTC');
require __DIR__.'/../vendor/autoload.php';
/////// CONFIG ///////
$username = 'xxxxxx';
$password = 'xxxxxx';
$debug = true;
$truncatedDebug = false;
//////////////////////
$ig = new InstagramAPIInstagram($debug, $truncatedDebug);
try {
$ig->login($username, $password);
} catch (Exception $e) {
echo 'Something went wrong: '.$e->getMessage()."n";
exit(0);
}
$loop = ReactEventLoopFactory::create();
if ($debug) {
$logger = new MonologLogger('rtc');
$logger->pushHandler(new MonologHandlerStreamHandler('php://stdout', MonologLogger::INFO));
} else {
$logger = null;
}
$rtc = new InstagramAPIRealtime($ig, $loop, $logger);
$rtc->on('live-started', function (InstagramAPIRealtimePayloadLiveBroadcast $live) {
printf('[RTC] Live broadcast %s has been started%s', $live->getBroadcastId(), PHP_EOL);
});
$rtc->on('live-stopped', function (InstagramAPIRealtimePayloadLiveBroadcast $live) {
printf('[RTC] Live broadcast %s has been stopped%s', $live->getBroadcastId(), PHP_EOL);
});
$rtc->on('direct-story-created', function (InstagramAPIResponseModelDirectThread $thread) {
printf('[RTC] Story %s has been created%s', $thread->getThreadId(), PHP_EOL);
});
$rtc->on('direct-story-updated', function ($threadId, $threadItemId, InstagramAPIResponseModelDirectThreadItem $threadItem) {
printf('[RTC] Item %s has been created in story %s%s', $threadItemId, $threadId, PHP_EOL);
});
$rtc->on('direct-story-screenshot', function ($threadId, InstagramAPIRealtimePayloadStoryScreenshot $screenshot) {
printf('[RTC] %s has taken screenshot of story %s%s', $screenshot->getActionUserDict()->getUsername(), $threadId, PHP_EOL);
});
$rtc->on('direct-story-action', function ($threadId, InstagramAPIResponseModelActionBadge $storyAction) {
printf('[RTC] Story in thread %s has badge %s now%s', $threadId, $storyAction->getActionType(), PHP_EOL);
});
$rtc->on('thread-created', function ($threadId, InstagramAPIResponseModelDirectThread $thread) {
printf('[RTC] Thread %s has been created%s', $threadId, PHP_EOL);
});
$rtc->on('thread-updated', function ($threadId, InstagramAPIResponseModelDirectThread $thread) {
printf('[RTC] Thread %s has been updated%s', $threadId, PHP_EOL);
});
$rtc->on('thread-notify', function ($threadId, $threadItemId, InstagramAPIRealtimePayloadThreadAction $notify) {
printf('[RTC] Thread %s has notification from %s%s', $threadId, $notify->getUserId(), PHP_EOL);
});
$rtc->on('thread-seen', function ($threadId, $userId, InstagramAPIResponseModelDirectThreadLastSeenAt $seenAt) {
printf('[RTC] Thread %s has been checked by %s%s', $threadId, $userId, PHP_EOL);
});
$rtc->on('thread-activity', function ($threadId, InstagramAPIRealtimePayloadThreadActivity $activity) {
printf('[RTC] Thread %s has some activity made by %s%s', $threadId, $activity->getSenderId(), PHP_EOL);
});
$rtc->on('thread-item-created', function ($threadId, $threadItemId, InstagramAPIResponseModelDirectThreadItem $threadItem) {
printf('[RTC] Item %s has been created in thread %s%s', $threadItemId, $threadId, PHP_EOL);
});
$rtc->on('thread-item-updated', function ($threadId, $threadItemId, InstagramAPIResponseModelDirectThreadItem $threadItem) {
printf('[RTC] Item %s has been updated in thread %s%s', $threadItemId, $threadId, PHP_EOL);
});
$rtc->on('thread-item-removed', function ($threadId, $threadItemId) {
printf('[RTC] Item %s has been removed from thread %s%s', $threadItemId, $threadId, PHP_EOL);
});
//...
$rtc->start();
$loop->run();