seregazhuk/php-pinterest-bot

Pin Search Order By?

Closed this issue · 4 comments

Hi, is there any way to get new pins from search function?

I get same content always.

$bot->pins->search('keyword')->toArray();

Hi,
You got pin date information from that command then you can sort based on pin date.
The easiest way, put the result on datatable which has sort feature

The search result from Pinterest will give the results determined by the Pinterest algorithm.
There may be no changes if Pinterest decides that no new pins should be added to the results.
You could sort the results by date I guess?

$sdata = $bot->pins->search('content marketing', 10) ->toArray();

//sort by date ...sort descending since the highest timestamp value will be the most recent
array_multisort(array_map(function($pdate) {
return strtotime($pdate['created_at']);
}, $sdata), SORT_DESC, $sdata);
//print the array
//echo '

';
//print_r($sdata);
//or just output some info..
foreach($sdata as $pininfo){

echo 'Pin Created: ' .$pininfo[created_at]. ' - Pin ID: '.$pininfo[id].'<br/>';

}

Sample output:
Pin Created: Wed, 10 Jul 2019 20:51:33 +0000 - Pin ID: 128985976815074506
Pin Created: Tue, 09 Jul 2019 23:01:48 +0000 - Pin ID: 579979258244522748
Pin Created: Sat, 06 Jul 2019 15:51:50 +0000 - Pin ID: 764626842966139596
Pin Created: Mon, 13 May 2019 07:01:30 +0000 - Pin ID: 808325833099539056
Pin Created: Thu, 11 Apr 2019 07:16:23 +0000 - Pin ID: 816770082399980298
Pin Created: Fri, 04 Jan 2019 16:47:46 +0000 - Pin ID: 182466222388802357
Pin Created: Sat, 15 Dec 2018 15:32:02 +0000 - Pin ID: 143481938115387621
Pin Created: Sat, 15 Dec 2018 15:22:44 +0000 - Pin ID: 22236591896635921
Pin Created: Mon, 19 Nov 2018 10:27:28 +0000 - Pin ID: 448530444135829870
Pin Created: Wed, 07 Jan 2015 04:10:32 +0000 - Pin ID: 172403491961041593