Closed diastowo29 closed 5 years ago
Hey,
Take a look at the example/inbox-thread-iterator.php.
Here is an example on how to send a message to a thread.
// Retrieve the inbox envelope
$envelope = $instagram->inbox();
// Retrieve the inbox
$inbox = $envelope->getInbox();
// Retrieve the available threads
$threads = $inbox->getThreads();
// Pick the first thread in the inbox
$thread = current($threads);
$thread->sendMessage('Hello!');
thanks for the reply, the sendMessage
part was successful, thanks for that, but i still can't get the whole conversation on each thread, i'll give you an example:
if someone send direct message to me like "Hello.." *and then send, and he send another message "who are you?" and he send it too, now when i debug $thread = current($threads);
part, its only showing me the "who are you?" items on the threads, its doesn't give me the "Hello.." items,
yes it was sent from a different timestamp, but is that how its work? we only get the last items only?
The key part is the $thread->whole()
part of the example. The API request behind the getInbox()
method only returns the latest ThreadItem
for every Thread
.
Inorder to retrieve additional messages,ThreadItem
, you need to call the whole()
method. You can also retrieve older message using $thread->next()
.
// Invoke the request
$envelope = $instagram->inbox();
// Retrieve the inbox
$inbox = $envelope->getInbox();
// Retrieve the first thread in the inbox
$thread = current($inbox->getThreads());
// Retrieve the whole thread including thread items
$thread->whole();
// Iterate through the list of items
foreach ($thread->getItems() as $item) {
var_dump($item->getText());
}
thats it !! thanks for your help.. one more, is it able to get media such as video, image, or the story of user who mentioned us on the inbox?
// Iterate through the list of items
foreach ($thread->getItems() as $item) {
// Check whether the item is of type media
if ($item->isItemType(ItemType::MEDIA)) {
// Retrieve the images
$images = $item->getMedia()->getImages()->getCandidates();
foreach ($images as $image) {
// Output the image url
var_dump($image->getUrl());
}
}
}
You might be able to retrieve video. I haven't tried yet.
alright, thanks Nicklas..
hey, can we get the whole conversation on inbox? i try to debug the
$envelope->getInbox();
and i just see the last conversation, so when there is 2 conversation on each thread, i only see the last one, the first one didn't show up.. thanks,one more thing, i couldn't get any example to implement sendText() method, i want to try sending a direct message to user, any help would be appreciated.. thanks