I listed the messages in My App successfully. Now I need to paginate the messages (about 8 in every page). I followed the doc of google but it only gives a pageToken but how to make it work?
If you list messages , and there still are more results to fetch, the response will contain a nextPageToken
.
Request
userId = me
maxResults = 8
GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=8&access_token={YOUR_API_KEY}
Response
{
"messages": [
{
"id": "151596a5055b9412",
"threadId": "151596a5055b9412"
},
{
"id": "1515915d0fcfd685",
"threadId": "1515915d0fcfd685"
},
{
"id": "15158e6826ed7587",
"threadId": "15158e6826ed7587"
},
{
"id": "15158e0e37572671",
"threadId": "15158e0e37572671"
},
{
"id": "151586443b5b309a",
"threadId": "151586443b5b309a"
},
{
"id": "15157c4b11732c5c",
"threadId": "1510f004b81a9de2"
},
{
"id": "151576512d37c9ec",
"threadId": "1515765122918d37"
},
{
"id": "1515765122918d37",
"threadId": "1515765122918d37"
}
],
"nextPageToken": "01770178536732383613", // Here it is!
"resultSizeEstimate": 26
}
Just include this value as the pageToken
in the next request.
Request
userId = me
maxResults = 8
pageToken = 01770178536732383613
GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=8&pageToken=01770178536732383613&access_token={YOUR_API_KEY}
Response
{
"messages": [
{
"id": "1515762549119366",
"threadId": "1513f096ab90fdab"
},
{
"id": "15157616d03a66a1",
"threadId": "1513f096ab90fdab"
},
{
"id": "151575f958ac69e8",
"threadId": "1513338849950602"
},
{
"id": "1515756737710843",
"threadId": "1515756737710843"
},
{
"id": "1515756735412b45",
"threadId": "1515756735412b45"
},
{
"id": "1515756710eed602",
"threadId": "1515756710eed602"
},
{
"id": "15157567089a24b0",
"threadId": "15157567089a24b0"
},
{
"id": "151574a87fefe71d",
"threadId": "151336e890f46a2c"
}
],
"nextPageToken": "13534757816909071635",
"resultSizeEstimate": 27
}
When there is no nextPageToken
in the response you have fetched every result there is.
我找到的解决方案是将所有令牌存储在前面的数组中,它使您能够在页面之间前进和后退,作为页面数组的索引,如果它没有给您带来 nextPageToken 它是因为它是最后一个,那么您将当前令牌(您所在页面的)作为参数传递,它会为您带来该页面的电子邮件列表。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.