facebook / facebook-php-business-sdk

PHP SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
815 stars 512 forks source link

Cursor UseImplicitFetch duplicates AbstractObject #60

Closed ferc closed 9 years ago

ferc commented 9 years ago

If I walk all Abstract Objects with 'useImplicitFectch' activated, when the API fetches the next page the new current object is the last object in previous page.

My example with CustomAudiences:

\FacebookAds\Cursor::setDefaultUseImplicitFetch(true);

$adAccount = new \FacebookAds\Object\AdAccount('act_xxx');

/** @var \FacebookAds\Cursor $cursor */
$cursor = $adAccount->getCustomAudiences(array(
    \FacebookAds\Object\Fields\CustomAudienceFields::ID
));

while ($cursor->key() !== null) {
    /** @var \FacebookAds\Object\CustomAudience $customAudience */
    $customAudience = $cursor->current();
    $customAudienceId = $customAudience->{\FacebookAds\Object\Fields\CustomAudienceFields::ID};

    echo "{$customAudienceId} - {$cursor->count()}\n";

    $cursor->next();
}

Prints: 001 - 25 002 - 25 ... 024 - 25 025 - 25 025 - 50 026 - 50 ...

pruno commented 9 years ago

hi @ferc,

i was able to reproduce this. I'll be sending out a fix asap.