androidapifacebook-graph-apifacebook-android-sdk

Facebook Graph API Request for only todays photos


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.


Solution

  • 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