In the previous articles, we have created a script that makes pins every five minutes and uses multiple accounts. But this is not enough, nobody will see your pins if you have no subscribers and nobody follows you. So, in this article are going to comment, like and repin other users pins. We are going to use a library called Pinterest Bot for PHP.
Before we start
Every action that we are going to perform requires pins. We need something to comment/like/repin. So the first thing we need is to find some pins. For example, we are targeted on cats topics and we need pins related to cats. We can search for them.
Now, we have an array of pins stored in our
Paginationobject. This object makes a request to Pinterest and receives results according to their pagination (20 items on the page). To get all the results at once as an array we use method
toArrayhere. You can find more information about
We start with the most simple thing - likes. Every item in
$pins array now contains a lot of different information about every pin we have found, but we only need an id. Next step is to put like on every pin in this array.
Very simple, right? Only one line of code to create a like.
Repins are very similar, the only difference is that we need to provide a board id, where we want to put this pin. So, it looks like we need a board. Let’s create one:
Now we can receive its id. Method
info accepts your username and a board title and returns an array of board data. We can find
So, now we are ready to make repins:
And again at least one line to repin to your board. Very simple!
The final step is to make comments. At first, we need some sort of dictionary for our comments. Everybody likes good comments. We are not going to disappoint anyone.
You can continue this list as you wish, but for this demo, this is enough. We will randomly select a word and write it as a pin comment.
And here is the final script, that put likes, makes repins and writes comments:
Done! Very simple. So much functionality and so little code.
We have covered the only bot functionality here, but this script may be improved a lot. For example, we can store in a database our comments, likes and repins history. It will be very useful if you want to look and behave as a real person and not a bot. For example, it looks silly if you write your comment twice on the same pin. Comments history can help us to skip pins that we have already commented. That same is true with likes and repins. There is no need to repin the same pin again and again.
You can find examples from this article on GitHub.