我们有一个简单的示例代码作为realtime
客户端mgp-instagram
私有api
到examples
名为的目录中realtimeClient.php
从等待接收某些命令的命令行运行此文件后,rtc
例如
live-started
,thread-created
然后当我从任何人那里获得新线程或当我们的线程用新消息更新时,我在终端中没有得到任何结果和输出
任何人都可以帮助我我怎样才能得到这个动作?接收新消息或更新线程
<?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 \InstagramAPI\Instagram($debug, $truncatedDebug);
try {
$ig->login($username, $password);
} catch (\Exception $e) {
echo 'Something went wrong: '.$e->getMessage()."\n";
exit(0);
}
$loop = \React\EventLoop\Factory::create();
if ($debug) {
$logger = new \Monolog\Logger('rtc');
$logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::INFO));
} else {
$logger = null;
}
$rtc = new \InstagramAPI\Realtime($ig, $loop, $logger);
$rtc->on('live-started', function (\InstagramAPI\Realtime\Payload\LiveBroadcast $live) {
printf('[RTC] Live broadcast %s has been started%s', $live->getBroadcastId(), PHP_EOL);
});
$rtc->on('live-stopped', function (\InstagramAPI\Realtime\Payload\LiveBroadcast $live) {
printf('[RTC] Live broadcast %s has been stopped%s', $live->getBroadcastId(), PHP_EOL);
});
$rtc->on('direct-story-created', function (\InstagramAPI\Response\Model\DirectThread $thread) {
printf('[RTC] Story %s has been created%s', $thread->getThreadId(), PHP_EOL);
});
$rtc->on('direct-story-updated', function ($threadId, $threadItemId, \InstagramAPI\Response\Model\DirectThreadItem $threadItem) {
printf('[RTC] Item %s has been created in story %s%s', $threadItemId, $threadId, PHP_EOL);
});
$rtc->on('direct-story-screenshot', function ($threadId, \InstagramAPI\Realtime\Payload\StoryScreenshot $screenshot) {
printf('[RTC] %s has taken screenshot of story %s%s', $screenshot->getActionUserDict()->getUsername(), $threadId, PHP_EOL);
});
$rtc->on('direct-story-action', function ($threadId, \InstagramAPI\Response\Model\ActionBadge $storyAction) {
printf('[RTC] Story in thread %s has badge %s now%s', $threadId, $storyAction->getActionType(), PHP_EOL);
});
$rtc->on('thread-created', function ($threadId, \InstagramAPI\Response\Model\DirectThread $thread) {
printf('[RTC] Thread %s has been created%s', $threadId, PHP_EOL);
});
$rtc->on('thread-updated', function ($threadId, \InstagramAPI\Response\Model\DirectThread $thread) {
printf('[RTC] Thread %s has been updated%s', $threadId, PHP_EOL);
});
$rtc->on('thread-notify', function ($threadId, $threadItemId, \InstagramAPI\Realtime\Payload\ThreadAction $notify) {
printf('[RTC] Thread %s has notification from %s%s', $threadId, $notify->getUserId(), PHP_EOL);
});
$rtc->on('thread-seen', function ($threadId, $userId, \InstagramAPI\Response\Model\DirectThreadLastSeenAt $seenAt) {
printf('[RTC] Thread %s has been checked by %s%s', $threadId, $userId, PHP_EOL);
});
$rtc->on('thread-activity', function ($threadId, \InstagramAPI\Realtime\Payload\ThreadActivity $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, \InstagramAPI\Response\Model\DirectThreadItem $threadItem) {
printf('[RTC] Item %s has been created in thread %s%s', $threadItemId, $threadId, PHP_EOL);
});
$rtc->on('thread-item-updated', function ($threadId, $threadItemId, \InstagramAPI\Response\Model\DirectThreadItem $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();