seregazhuk / php-pinterest-bot

This PHP library will help you to work with your Pinterest account without using any API account credentials.
MIT License
413 stars 129 forks source link

Pull only public boards #417

Closed code200 closed 5 years ago

code200 commented 6 years ago

Hello:

$boards = $bot->boards->forMe(); $boards = $bot->boards->forUser($me_username);

Is it possible to get a list of ONLY public boards (Not secret)?

If so, please share the code. Thanks!

code200 commented 5 years ago

Hi, I see that you can create private boards: // Create a private board $bot->boards->createPrivate('Name', 'Description');

and pass more options in an update: $bot->boards->update($boardId, [ 'name' => 'New title', 'description' => 'New description', 'privacy' => 'secret', 'category' => 'sports', ]);

But I would like to select (get) boards that are NOT secret only.

Can you please tell me where to update this code? Or if this is possible?

Please assign the label for this post as a question.

Thank you.

seregazhuk commented 5 years ago

Hi! There is no need to update the code. Just filter the received boards by privacy field.

2018-09-23 8 46 03
code200 commented 5 years ago

Hello! I would like to adjust the code in a plugin that someone created based on your code. I would only like to pull public boards and randomly pin to one of them. The plugin is pulling all boards (secret too). Basically I don't want to pin to secret boards.

Here's a snippet: $boards = $bot->boards->forMe(); $boards = $boards[array_rand($boards)]; $boardId = $boards['id'];

Any ideas how I can pull (or filter) so my array has only public boards (no secret boards)?

Thanks!

seregazhuk commented 5 years ago

Try this:

$boards = $bot->boards->forMe();
$onlyPublicBoards = array_filter($boards, function (array $board) {
    return $board['privacy'] === 'public';
});
code200 commented 5 years ago

I only got to test it once so far but it seems to be working well. Thank you very much!