I want to get all the uploaded photos of the logged in user that was uploaded today. I could fetch all the photos and filter it with the created_time field. But I would like to make the request to Facebook api to just send me todays photos.
This is the code I am using to get users uploaded photos
fun getAllPhotos() {
val bundle =Bundle()
bundle.putString(
"fields",
"album,alt_text,created_time,event,place,alt_text_custom,name,name_tags,target,source"
)
tempPhotos.clear()
val request = GraphRequest.newGraphPathRequest(
AccessToken.getCurrentAccessToken(),
"/me/photos/uploaded",
object : GraphRequest.Callback {
override fun onCompleted(response: GraphResponse) {
val type = object : TypeToken<ApiResponseObject>() {}.type
val respJSON = response.getJSONObject()
val item: ApiResponseObject = Gson().fromJson(respJSON.toString(), type)
item.data.forEach {
if (UtilityFunctions.checkIfToday(it.createdTime)) {
tempPhotos.add(it)
} else {
return@forEach
}
}
}
})
request.parameters = bundle
request.executeAsync()
}
As you can see I request for all photos to "/me/photos/uploaded/" I would like to only request for photos on a certain date ( or just today )
I saw that the response came sorted by created time so I returned from the loop whenever I saw some picture that was out of date.
2
Answers
I found the solution. I just needed to look into the pagination documentation I found that just as fields I could also send since and a unix timestamp and it would return the photos uploaded since that timestamp
Hey can you provide some more information regarding the issue you are facing with your code.
eg. some examples of how facebook api response structure is, some code snippets etc.
I crawled a while for the internet to search for your problem as it is difficult to create custom query in graph api and I have never used it before. What you are doing in your code is not bad either but if you insist on creating a custom query to api then I have found a github repository that might help you
Facebook Graph API query builder