Build Pinterest Bot with PHP: Multiple Accounts and Proxy
In the previous post, we have created a small script to automate pins creation on Pinterest. It uses only one your account, but what if you have several accounts and want to use them all. And of course, it is a good practice to use a proxy, because it looks suspicious when you frequently create pins from different accounts but from one IP.
Let’s consider that we have two accounts. One for cats and another for dogs. Each account has it’s our credentials, folder with images, keywords dictionary and promoting link (for example a blog). We place them in a separate accounts.php file in the same directory without pin.php file, from the previous post. This file will be used as accounts config.
Then in we need to require it in our pin.php.
Now, all our accounts data is stored in $accounts variable. Next step is to modify existing code and replace hardcoded account data. To make it simple, we will loop through our accounts and for every account, we will create pins. Now let’s refactor a bit our pin.php file. We can extract a function for selecting an image and put it in a separate file functions.php:
And again we need to require it in our main script:
Now, we are ready to add a loop through our accounts and replace all the hardcoded values:
Next step is a proxy. Assume, that we will use one IP for each account. So, we need to update our accounts.php config and add proxy data there:
Perfect. Then we need to tell our bot to use a proxy. Here is a full documentation about proxy usage. Only one line change is required to use a proxy:
Very easy, right? So, the final version for our pin.php script, now with multiple accounts and proxy:
Congratulations! We have upgraded our script. Now it is more flexible, we can add new accounts to it, without modifying the entire script. It is also easy to set up proxy connections for our accounts.
You can find examples from this article on GitHub.