Closed izdrail closed 4 years ago
According to the public docs, errors in responses are treated as objects which have a "title" property, except when you get a 401 HTTP response status. This has not been coded in the PHP API wrapper.
Maybe you have an authentication/authorization issue. Sharing some code would help.
!!! Later edit: Oops, never mind, I just noticed that the actual error was different. But if that's the case, I would expect a 429 HTTP status code, which, according to the same docs, should produce an errors
array, each object having a title
property.
Maybe the docs are slightly outdated.
` $this->info('We started the process');
$me = new Affiliate('email', 'pass'); // fill in with your own credentials
$filterAffiliates = new AffiliateFilter() ;
$filterAffiliates->setFilteredFields('accepted');
$filterAffiliatesProgramFeed = new ProductFeedsFilter();
$filterProducts = new ProductFilter();
$affiliates = collect([]);
try{
foreach ($me->getPrograms($filterAffiliates) as $affiliateProgram){
$affiliate = new \LzoMedia\Classified\Entity\Affiliate($affiliateProgram);
if($affiliate->isActive()){
$filterAffiliatesProgramFeed->setFilteredFields($affiliate->getAffiliateId());
$affiliateProgramProductsFeed = $me->getProductFeeds();
$products = [];
foreach ($affiliateProgramProductsFeed as $programFeed){
$tmp = new ProductFeed($programFeed);
for($page = 1; $page <= 5; $page++) {
$filterProducts->setFilteredFields([
'page' => $page,
'query' => [
'name' => '%jucarii%'
]
]);
$products[$page] = $me->getProducts($tmp->getId(),$filterProducts);
}
}
}
}
}catch (APIException $exception){
}
dd($products);`
my code from your error I guess I got banned by the API or something. all the custom classes that you are seeing i'm just extending from the base class.
I'm guessing this is the culprit $products[$page] = $me->getProducts($tmp->getId(),$filterProducts);
that generates the exception (you can follow the stack trace to check).
I've edited my previous reply. And here's a quote from the docs:
This is part of the throttled endpoints.
You can make a maximum of 100 requests to these endpoints per minute. The endpoints will have a common request count.
When you reach the threshold, a 5 minute penalty will be applied. The server will return 429(Too many requests) status during this time.
So yeah, you got banned by the API server :) However, you should have received a proper error message, readable from the API response, and that's the PHP wrapper's job, but it relies on what the API documentation says.
I'm trying to extract the products from the API, I've managed to double down and make my system work so far and now after a couple of testing I'm getting an error:
In ApiResponse.php line 110: Trying to get property 'title' of non-object
after going on that line:
if($data && isset($data->errors) && (is_array($data->errors) || $data->errors instanceof Traversable)) { $message = []; foreach ($data->errors as $error) { print_r($error); die;
I'm getting:
"Too many requests"
which is just a string