Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Unable to see Comments array data in Pin array #361

Closed
ltiwana opened this issue Mar 20, 2018 · 15 comments
Closed

Unable to see Comments array data in Pin array #361

ltiwana opened this issue Mar 20, 2018 · 15 comments
Assignees

Comments

@ltiwana
Copy link

ltiwana commented Mar 20, 2018

I was able to see the comments array in pins array, but it seems it isn't displayed anymore.


Array

(
     [bookmark] => LT42OTM4Mzg1NjYzNzE4OTA4ODo1fDIxNzNhNzViMWEzNDhmMGIwN2RhNTRhMjU2YjcwODJjZTVkYzdiYWFmNzcyMjE2Zjg5NGMzOTVhNDZjMzAyOGM=
    [data] => Array
         (
         )

     [uri] => /v3/pins/69383650488493124/comments/
 )
@seregazhuk
Copy link
Owner

Can you show the code please?

@ltiwana
Copy link
Author

ltiwana commented Mar 21, 2018

Sorry for not adding the code I know you have specified this in the instructions.

here is my code:
date_default_timezone_set('America/Toronto');
require __DIR__ . '/vendor/autoload.php';
use seregazhuk\PinterestBot\Factories\PinterestBot;

$bot = PinterestBot::create();

$pins = $bot->pins->search('security', 20)->toArray();

foreach($pins as $pin) {
print_r ($pin['comments']);
}

@seregazhuk
Copy link
Owner

@ltiwana Looks like it is on Pinterest side. Their response doesn't contain comments data
comments

@ltiwana
Copy link
Author

ltiwana commented Mar 22, 2018

Oh okay, so there is no way to know if I have already commented on the pin.

@seregazhuk
Copy link
Owner

Update to version 5.6.9 and use this code.

@ltiwana
Copy link
Author

ltiwana commented Mar 22, 2018

@seregazhuk Just tried again. Here is the error i get:

PHP Fatal error: Uncaught seregazhuk\PinterestBot\Exceptions\InvalidRequest: Error calling seregazhuk\PinterestBot\Api\Providers\Comments::getList method. Method getList does'n exist. in C:\Users\ltiwana\Documents\GitHub\php-pinterest-bot\vendor\seregazhuk\pinterest-bot\src\Api\Providers\Core\ProviderWrapper.php:48
Stack trace:
#0 C:\Users\ltiwana\Documents\GitHub\php-pinterest-bot\Test.php(93): seregazhuk\PinterestBot\Api\Providers\Core\ProviderWrapper->__call('getList', Array)
#1 {main}
thrown in C:\Users\ltiwana\Documents\GitHub\php-pinterest-bot\vendor\seregazhuk\pinterest-bot\src\Api\Providers\Core\ProviderWrapper.php on line 48

Here is my code:

date_default_timezone_set('America/Toronto');
require __DIR__ . '/vendor/autoload.php';
use seregazhuk\PinterestBot\Factories\PinterestBot;

$bot = PinterestBot::create();
$pins = $bot->pins->search('cats', 100)->toArray();

foreach($pins as $pin) {
			
	$comments = $bot->comments->getList($pin['id'])->toArray();

	foreach($comments as $comment) {
		print_r ($comment);
		sleep (2);
	}
}
		

@seregazhuk
Copy link
Owner

Looks like you haven't updated to 5.6.9

@ltiwana
Copy link
Author

ltiwana commented Mar 23, 2018

I believe i am using the latest.
From changelog.md, it shows me the following comment:

# Change Log
All notable changes to this project will be documented in this file.

## v5.6.9 - 2018-03-21
### Added:
 - get comments for a specified pin

and pins.md has modify date of today 3/22/2018 12:56PM.

@seregazhuk
Copy link
Owner

I've just created an empty project, required the library and everything is ok 😕

@ltiwana
Copy link
Author

ltiwana commented Mar 27, 2018

I am setting it up on a new system from scratch. Hopefully, it works.

@seregazhuk
Copy link
Owner

@ltiwana does it work for you?

@ltiwana
Copy link
Author

ltiwana commented Mar 29, 2018

@seregazhuk this is fixed, and working on the new project.

My problem was that I wanted to make sure that i don't end up with duplicate comments on the same pin. So I used the comment array to check if my name is under comments. Is there a better way to find that out?

@seregazhuk
Copy link
Owner

@ltiwana I don't know :( They have removed this array from response. So, let me know If you have any ideas.

@ltiwana
Copy link
Author

ltiwana commented Mar 29, 2018

@seregazhuk Actually your bot was the reason I got started with PHP (awesome job on the bot). I have never used PHP before but I will try my best to help out.

Here is my code that I use to find out if I have already commented on a pin:

<?php

date_default_timezone_set('America/Toronto');

require __DIR__ . '/vendor/autoload.php';
use seregazhuk\PinterestBot\Factories\PinterestBot;

$comments = ["love this post!", "Very valuable info!", "Very good info!", "This is good info!"];
$pinwords = ['cybersecurity', 'ransomware', 'antivirus technology'];

$bot = PinterestBot::create();
$result = $bot->auth->login('username','password');

$countpinwords = 1;
$seconds = range(60,180);

print "\n\n\n\n\n\n\n" . date('Y-m-d h:i:s') . " - INFO     - Grabbing all your saved pins, this may take some time. Please wait...\n";

//I use this to find out if I have already repinned a pin
$alreadypin = $bot->pinners->pins('username',10000)->toArray();

foreach($pinwords as $pinword) {
	
	print "\n\n\n\n\n\n\n*******************************************************************\n";
	print date('Y-m-d h:i:s') . " - INFO     - Searching for \"$pinword\" pins...\n";
	print date('Y-m-d h:i:s') . " - INFO     - At $countpinwords out of " . count($pinwords) . " Pinwords...\n\n\n\n";	
	print date('Y-m-d h:i:s') . " - ACTION   - Searching for $searchpin pins of word \"$pinword\". Please wait, this may take some time...\n";
	
	$pins = $bot->pins->search($pinword, $searchpin)->toArray();
	$countpins = 1;
	
	foreach($pins as $pin) {    
		
		print "\n\n\n\n\n\n\n*******************************************************************\n";
		print date('Y-m-d h:i:s') . " - INFO     - Pin Details: \n";
		print date('Y-m-d h:i:s') . " - INFO     - At $countpinwords out of " . count($pinwords) . "  Pinwords...\n";
		print date('Y-m-d h:i:s') . " - INFO     - At $countpins out of " . count($pins) . " Pins...\n\n";
		
		$countpins = 1;
		
		foreach($pins as $pin) {
			
			$comments = $bot->comments->getList($pin['id'])->toArray();
			$comtest = 'No';
			
			print date('Y-m-d h:i:s') . " - INFO     - Checking if already commented...";	
			
			foreach($comments as $comment) {
				
				if ($comment['user']['id'] == 'YourUserID') {
					$comtest = 'Yes';
					echo "$comtest\n";
					print date('Y-m-d h:i:s') . " - SKIPPING - Already commented!...\n";
					print date('Y-m-d h:i:s') . " - INFO     - Your Comment ID   -> {$comment['comments']['id']}\n";
					print date('Y-m-d h:i:s') . " - INFO     - Your Comment Text -> {$comment['comments']['text']}\n\n";
				}
			}
			
			if ($comtest == 'No') {
				echo "$comtest\n";
				
				$comment = $comments[array_rand($comments)];
				
				print date('Y-m-d h:i:s') . " - INFO     - No comments found\n";
				print "\n\n\n\n" . date('Y-m-d h:i:s') . " - ACTION   - Posting comment       -> $comment...\n";
				print date('Y-m-d h:i:s') . " - INFO     - Commented Pin URL     -> https://www.pinterest.ca/pin/{$pin['id']}\n\n\n\n";
				
				$bot->comments->create($pin[id], 'Good info');
				$bot->comments->create($pin['id'], $comment);						
				$wait = $seconds[array_rand($seconds)];
				
				print date('Y-m-d h:i:s') . " - WAITING  - For $wait seconds...\n\n"; 
				sleep($wait);
				
			}
				
		}
		$countpins = $countpins + 1;
	}
	$countpinwords = $countpinwords + 1;	
}

@seregazhuk
Copy link
Owner

Close, because its not library issue, but Pinterest itself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants