NicklasWallgren / instagram-api

Instagram Private API
MIT License
147 stars 47 forks source link

Get the whole conversation on inbox #13

Closed diastowo29 closed 5 years ago

diastowo29 commented 5 years ago

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

NicklasWallgren commented 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!');
diastowo29 commented 5 years ago

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?

NicklasWallgren commented 5 years ago

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().

NicklasWallgren commented 5 years ago
// 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());
}
diastowo29 commented 5 years ago

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?

NicklasWallgren commented 5 years ago
// 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.

diastowo29 commented 5 years ago

alright, thanks Nicklas..