facebook / facebook-java-business-sdk

Java SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
402 stars 332 forks source link

ApiNodeList.nextPage requests one extra page when there's no more results #309

Closed pawel-dabro closed 3 years ago

pawel-dabro commented 4 years ago

Which SDK version are you using?

v. 7

What's the issue?

ApiNodeList.nextPage requests one additional page even when it's at the last page of results currently. Documentation in https://developers.facebook.com/docs/graph-api/using-graph-api/#paging states:

Stop paging when the next link no longer appears.

However, in that case ApiNodeList.nextPage falls back to cursor-based paging mechanism and only stops after retrieving an additional empty page with no cursor information.

Steps/Sample code to reproduce the issue

Use any graph edge that returns ApiNodeList like campaigns, that returns one or more pages of data

Observed Results:

For N pages of data, there is N+1 requests beign made. One final request is made when there is no next link, which results in a response with empty data array and no paging section. Only after that paging stops, even though it is apparent from the lack of next page in Nth response that N+1th request is not necessary.

Nth request

2020-09-21 13:06:33.743 ========Start of API Call========
2020-09-21 13:06:33.743 Request:
2020-09-21 13:06:33.743 GET: https://graph.facebook.com/v7.0/act_.../campaigns?acce
ss_token=...&fields=id%2Cname&limit=25&after=QVFIUkhyNWtiM1JJLTk5WEhRaWZAFc0F...&appsecret_proof=...
2020-09-21 13:06:33.831 Response:
2020-09-21 13:06:33.831 {"data":[
<LAST PAGE OF DATA RETURNED HERE>
],"paging":{"cursors":{"before":"QVFIUkVES3hiV0tyUjQ...","after":"QVFIUlJReDdpSDlOcHlGeUYzemhqNDRsYV..."},
"previous":"https:\/\/graph.facebook.com\/v7.0\/act_...\/campaigns?access_token=...&fields=id\u00252Cname&limit=25&before=QVFIUkVES3hi..."}}
2020-09-21 13:06:33.831 ========End of API Call========

N+1th request

2020-09-21 13:06:33.836 ========Start of API Call========
2020-09-21 13:06:33.837 Request:
2020-09-21 13:06:33.837 GET: https://graph.facebook.com/v7.0/act_.../campaigns?acce
ss_token=...&appsecret_proof=...&after=QVFIUlJReDdpSDlOcHlGeUYzemhqNDRsYV...&fields=id%2Cname
2020-09-21 13:06:33.887 Response:
2020-09-21 13:06:33.887 {"data":[]}
2020-09-21 13:06:33.887 ========End of API Call========

Expected Results:

ApiNodeList.nextPage should not make the extra (N+1th) request for empty page when it knows from its current state that there was no more data.

stale[bot] commented 3 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.