suphiyasin / instagram-api

Simple PHP Private API that allows you to use both mobile and web APIs of Instagram
https://suphi.org
MIT License
36 stars 11 forks source link

Get Medias by username #4

Closed arislanhaikal closed 6 months ago

arislanhaikal commented 7 months ago

Hi, I need some help to get medias I try to get user info with

$api->webapi->getUserInfoFromUsername($token, $username);

I see this user response include _edge_owner_to_timelinemedia But no medias edges included and with response empty array

Is there a special function to retrieve media?

Thank for your awesome tools

suphiyasin commented 7 months ago

Hello, I will be home in a few hours, I will test and get back to you.

suphiyasin commented 7 months ago

Hello, I did a review. The response of the mentioned getUserInfoFromUsername function contains only information about the username. If you want to receive media, you need to use the getFeed function from the mobile API. example: $api->user->getFeed(null, $userid);

arislanhaikal commented 7 months ago

Nice, What do you mean in manuel?

$api->manuel->getFeed(null, $userid);

This is only return the first 12 medias. Can it possible to get next page medias?

suphiyasin commented 7 months ago

There is next media id in the incoming response, you need to add it to the request. (copy and paste the function and edit the 2nd function)

arislanhaikal commented 7 months ago

Response getFeed function like this. How do I move to the next page?

CleanShot 2024-04-06 at 07 05 38

Can you elaborate function with example?

Sorry I ask many questions :)

suphiyasin commented 7 months ago

Hello, I am on holiday (it will last 1 week). After 1 week, write something here again and remind me, I will send you the new function.

arislanhaikal commented 6 months ago

Hi @suphiyasin, have you finished your holiday? I waiting for you

suphiyasin commented 6 months ago

Hello yes I am back, thank you for reminding me. I didn't have a chance to test it, but this code should work.

    public function getMoreMedia($userid = null, $nextmediaid){
        $userid = $userid ?? $this->userid;
        $url = $this->apibase.'/api/v1/feed/user/'.$userid.'/?exclude_comment=true&max_id='.$nextmediaid.'&only_fetch_first_carousel_media=false';
        $sendRequest = $this->getwithcookie($url, null);
        return $sendRequest;
    }