Facebook Graph api paging cursors - facebook-graph-api

In responce api i get data with cursors: "next" and "previous" ...
{
"data": [
... Endpoint data is here
],
"paging": {
"cursors": {
"after": "MTAxNTExOTQ1MjAwNzI5NDE=",
"before": "NDMyNzQyODI3OTQw"
},
"previous": "https://graph.facebook.com/{your-user-id}/albums?limit=25&before=NDMyNzQyODI3OTQw"
"next": "https://graph.facebook.com/{your-user-id}/albums?limit=25&after=MTAxNTExOTQ1MjAwNzI5NDE="
}
}
"Next" one is work well but "Previous" always return me a empty data.
{
data: [ ]
}
Is my mistake or Facebook?

Related

How Do I Set a Custom Range In Insight API?

First time using the Facebook API so sorry if easy question.
I figured out how to get the lifetime spend on an ad
GET REQUEST: me/adaccounts?fields=id,name,amount_spent,account_id,ad_studies{results_first_available_date},spend_cap
{
"data": [
{
"id": "<ID>",
"name": "<name>",
"amount_spent": "<spent>",
"account_id": "<id>",
"spend_cap": "<amount>",
"insights": {
"data": [
{
"cost_per_unique_click": "<cost>",
"date_start": "<start date>",
"date_stop": "<yesterday>"
}
],
"paging": {
"cursors": {
"before": "<some stuff>",
"after": "<some stuff>"
}
}
}
}
],
"paging": {
"cursors": {
"before": "<some stuff>",
"after": "<some stuff>"
}
}
}
But I want to set a range. In this example, it seems to give me when the campaign started, but I want to select my own range. And i dont see it anywhere in the graph explorer dropdown, such as a "from_time"
Where can I set a date range?

google-cloud-recommendation How to get next page for Prediction?

I want to use predict method in order to get recommendation devided by page.
This method has pageToken parameter used for paging. The parameter should be received in the previous prediction response.
But this method in v2 API doesn't return pageToken or nextPageToken that is in v1beta1 API.
Why it disappeared? How can I get next page for prediction?
Request url is
https://retail.googleapis.com/v2/projects/{PROJECT_NUMBER}/locations/global/catalogs/default_catalog/placements/recently_viewed_default:predict
Request body is
{
"filter": "tag=(\"成人作品\") filterOutOfStockItems",
"userEvent": {
"eventType": "home-page-view",
"visitorId": "1254704470.1607003607",
"productDetails": [
{
"product": {
"id": "220604"
},
"quantity": 1
}
]
}
}
The response is here. There is no nextPageToken
{
"results": [
{
"id": "170706"
},
{
"id": "64081"
},
:
(snip)
:
{
"id": "132940"
},
{
"id": "17557"
}
],
"attributionToken": "ChQxNzkzOTg1NDI3MTk1OTMyNzU0MhACGiNvZnRlbl9wdXJjX2ZyZXF1ZW50bHlfMTYxNDMwNjk3OTQyNSIYb2Z0ZW5fcHVyY2hhc2VkX3RvZ2V0aGVyKAA"
}

How to iterate and get the properties and values of a JSONAPI response in emberJS?

I have following ember request
this.store.createRecord('food_list',requestObj
).save().then((response) => {
console.log(response);
console.log(response.id); // This is working
console.log(response.food_list_code); //this does NOT work !!!!!
}
It will call an API and save a record to database and then returns following response.
{
"links": {
"self": "/api/food_list"
},
"data": {
"type": "",
"id": "da6b8615-3f4334-550544442",
"attributes": {
"food_list_date": "2013-02-14 23:35:19",
"food_list_id": "da6b8615-3f4334-550544442",
"food_list_code": "GORMA",
},
"relationships": {
"food_list_parameters": {
"data": [
{
"type": "food_list_parameter",
"id": "RERAFFASD9ASD09ASDFA0SDFASD"
}
]
},
"food_new_Name": {
"data": {
"type": "food_new_Name",
"id": "AKASDJFALSKDFKLSDF23W32KJ2L23"
}
}
},
"links": {
"self": "/api/BLAH/BLAH/BLAH"
}
}
}
but since above response is a JSONAPI in form of an ember object, I dont know how to parse it.
If I try to get response.id, I get the string da6b8615-3f4334-550544442
But how to get value for food_list_code in response block. Or how to iterate the response object to get "food_list_code" and "food_list_date" ?
The output for console.log(response) is as following ember class
Class {__ember1500143184544: "ember1198", store: Class, _internalModel: InternalModel, currentState...
I appreciate your help.
M.

How do you handle large relationship data attributes and compound documents?

If an article has several comments (think thousands over time). Should data.relationships.comments return with a limit?
{
"data": [
{
"type": "articles",
"id": 1,
"attributes": {
"title": "Some title",
},
"relationships": {
"comments": {
"links": {
"related": "https://www.foo.com/api/v1/articles/1/comments"
},
"data": [
{ "type": "comment", "id": "1" }
...
{ "type": "comment", "id": "2000" }
]
}
}
}
],
"included": [
{
"type": "comments",
"id": 1,
"attributes": {
"body": "Lorem ipusm",
}
},
.....
{
"type": "comments",
"id": 2000,
"attributes": {
"body": "Lorem ipusm",
}
},
]
}
This starts to feel concerning, when you think of compound documents (http://jsonapi.org/format/#document-compound-documents). Which means, the included section will list all comments as well, making the JSON payload quite large.
If you want to limit the number of records you get at a time from a long list use pagination (JSON API spec).
I would load the comments separately with store.query (ember docs), like so -
store.query('comments', { author_id: <author_id>, page: 3 });
which will return the relevant subset of comments.
If you don't initially want to make two requests per author, you could include the first 'page' in the authors request as you're doing now.
You may also want to look into an addon like Ember Infinity (untested), which will provide an infinite scrolling list and automatically make pagination requests.

What is the "likes" field from an FB Open Graph GET og.likes request?

I've implemented functionality to Like a non-FB URL in a cross-platform mobile app (Phonegap) I'm developing, and part of functionality is that I need to find out if a user has liked a URL before, hence a GET on the og.likes object. In the result of this request there's a field in the og.likes data that I'm unsure about.
My request:
GET me/og.likes?access_token={AccessToken}&object={EncodedExternalURL}
The response:
{
"data": [
{
"id": "_____",
"from": {
"id": "______",
"name": "______"
},
"start_time": "2015-01-12T06:17:24+0000",
"end_time": "2015-01-12T06:17:24+0000",
"publish_time": "2015-01-12T06:17:24+0000",
"application": {
"name": "______",
"namespace": "______",
"id": "______"
},
"data": {
"object": {
"id": "____",
"url": "____",
"type": "website",
"title": "____"
}
},
"type": "og.likes",
"no_feed_story": false,
"likes": { // <-- this guy here and its properties
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
}
],
"paging": {
"next": "____"
}
}
What is the likes field? And the sub properties of count, can_like, user_likes? Is it that other users can like this Like?
likes field is for manage the likes that this like has. Users can like or comment a like.