WP rest api: How to get number of comments - json

I read all the Wordpress WP rest api document but i did not find how to limit the numbers of comments i want.
I tryed. http://mywebsite.com/wp-json/posts/999/comments?filter[comments_per_page]=1

If you're able to use version 2 of the Rest API, then the endpoint is something like the following:
domain.com/wp-json/wp/v2/comments?post=1&per_page=2
where the post parameter is the ID of the post for which you're retrieving the comments and per_page is how many to show. If you want a list of all comments, and limit them, then:
domain.com/wp-json/wp/v2/comments?per_page=2
You can also append a page parameter to show a different paged value of comments thus:
domain.com/wp-json/wp/v2/comments?post=1&per_page=2&page=3
which would return the 5th and 6th comments (page 3 of comments when there are 2 per page) for the post with an ID of 1

Related

Unable to retrieve unlimited number of record via API

We are struggling to mine all time records for this year via API.
We have tried to include the :dont_limit_result GET variable and set it to 1, however it did not help us.
The version that we use is ACTIVE COLLAB 5.11.0, the URL we are hitting: projects?dont_limit_result=1&page=$page
Please give me some advise on how to proceed.
Most of API responses are paginated, and pagination can't be turned off using a GET switch. Instead, you should check following headers:
X-Angie-PaginationCurrentPage - indicates current page
X-Angie-PaginationItemsPerPage - indicates number of items per page
X-Angie-PaginationTotalItems - indicates number of items in the entire data set.
and walk through pages until you reach the end of data set.
Another option is to give project's filter a try. Here's an example request that will return all projects:
curl -H "X-Angie-AuthApiToken: YOUR-API-TOKEN" "http://your.activecollab.com/api/v1/reports/run?type=ProjectsFilter"
This one will return all active projects:
curl -H "X-Angie-AuthApiToken: YOUR-API-TOKEN" "http://your.activecollab.com/api/v1/reports/run?type=ProjectsFilter&completed_on_filter=is_not_set"
I'm using the php API wrapper 3.0 - how do i get the headers back to know there are more pages and then what is the correct form of the query to get further pages?
For example my basic query is:
$timeRecords = $client->get('projects/22/time-records')->getJson();
to get time records - but this only returns 100 and there are more!
Thanks,
P

Google Bigquery json API, pageToken has no effect

I'm trying to implement the JSON api (v2) of bigquery. In my code I get the same behaviour as on the documentation page for tabledata-list
My table size is about 11.000 rows. In the documentation page I fill in the following parameters:
ProjectId = X
DatasetId = Y
TableId = Z
MaxResults = 10000 #I want to paginate my results
This returns 10.000 rows and a pageToken. So I do the same request and now I set the page token so that I get the next page of results.
And that returns the same 10.000 rows as before. I expected this to do pagination as described on this page:
All collection.list methods return paginated results under certain circumstances. The number of results per page is controlled by the maxResults property
A page is a subset of the total number of rows. If your results are more than one page of data, the result data will have a nextPageToken property. To retrieve the next page of results, make another list call and include the token value as a URL parameter named pageToken.
Where do I go wrong?
EDIT:
My colleague pointed out to me that on the other documentation pages the result contains a nextPageToken except the response contains a pageToken. The difference being that where pageToken refers to the current page, the nextPageToken refers to the next page.
However the documentation states it should return a nextPageToken (except when there is no more data). But len(table) > len(result)
On the same page it's mentioned that there is a difference for TableData.List() call
The bigquery.tabledata.list method, which is used to page through
table data, uses a row offset value or a page token.
So for TableData.List() you must use the row offset value to paginate, and in order to access previous pages you can use your hashes from your session. This is built because with large volume and big data, you cannot pre-cache the next set of data from your worker pool.
You can help improving the documentation, by using the link on top right of each page that says: Feedback on this document feel free to use that to reach out with improvements.
Also you can submit issues to https://code.google.com/p/google-bigquery/issues/list
Unfortunately, the field returned for TableData.List() that contains the logical "next page token" is literally named "pageToken", rather than "nextPageToken".
Other APIs, like Datasets.List(), return a field literally named "nextPageToken" which contains the logical "next page token".
It's a case of inconsistent naming, but hopefully this helps clear up some confusion.

Amazon API, Get Title and Price

I am looking for a way to get the Prices and Titles of products using the Amazon's API Operation -> ItemSearch.
So far, I can get the Price using the ResponseGroup -> Offers.
1) Is there any way to get a product title without the API, using the ASIN? For example some kind of url amazon.com/titles/id
2) If not, how can I get the Title without increesing the filesize of the xml returned too much?
1) According to the ASIN wikipedia page, the shortest format URL you can create would be http://amzn.com/ASIN with 'ASIN' being the actual number. If you wanted to parse the HTML returned from a link to find the title, that is another possible option.
2) Add the ItemAttributes response group; you can comma-delimit response groups too so ResponseGroup -> Offers,ItemAttributes is what I'd suggest.
And if ItemAttributes increases filesize too dramatically, you can find a list of valid response groups on the ItemSearch operation page in the docs.

Plugin WordPress JSON API - How get posts for category with offset?

for example in category "news" of my blog there are 50 posts.
For get last 10 posts I do:
http://mywordpress.com/?json=get_category_posts&slug=news&count=10&status=publish
And it work correctly.
Now I want to get my posts from 11 to 20 skipping last 10 posts, etc.
How can I do?
The post count defaults to whatever you set in the wordpress backend (settings -> reading). You can achieve pagination by just adding the page parameter. So if you want the posts 11-20 you just call
http://mywordpress.com/?json=get_category_posts&slug=news&count=10&status=publish&page=2
You find more information here: JSON API Plugin Page, Other Notes
You can't use get_category_posts with offset.
You have to construct the query from the basic get_posts which has a lot of parameters, see here:
http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
and here (read Method: get_posts):
http://wordpress.org/plugins/json-api/other_notes/
I think you should use something like:
blablabla.xxx/?json=get_posts&count=10&status=published&cat='id of the category news'&offset='int offset'
Be aware that use offset 'breaks' pagination

facebook graph comments filter and summary

I'm trying to retrieve only top-level comments with a count or all comments (including replies) for a given post from the Facebook graph.
Has anyone got the Facebook graph comment filter or summary fields on comment graph calls to work? It says in the docs https://developers.facebook.com/docs/graphapi/guides/comments/ you can add a ?filter=stream and or ?summary=true to the graph url to include comment replies and or summary information (counts) in the collection of returned comments.
A hypothetical example is: for a public feed Facebook will tell you that a post has 100 comments and this number includes replies, when you actually retrieve the comments you may only get back 80 because the graph only returns top-level comments not comments and their replies.
Real example
graph.facebook.com/10151579052696276/comments/
gets all the first 25 comments from a post (using the object_id) but excludes replies. It only returns top level comments. This is a problem because the post comment count Facebook returns doesn't match the number of comments it returns. If you try and make comment pagination your screwed because its inconsistent.
To fix this i tried to add the filter stream and summary
graph.facebook.com/10151579052696276/comments/?filter=stream&summary=true
returns the exact same JSON.
I've tried including user access tokens (with all permissions) and an app token
try it yourself in the graph explorer https://developers.facebook.com/tools/explorer/
Any help would be much appreciated.
Your request Url is wrong
Delete "/" after "comments"
url should be like this;
graph.facebook.com/10151579052696276/comments?filter=stream&summary=true
Here's your answer:
>> For Comment Counts with their replies:
https://graph.facebook.com/80329313253_10153617216088254/comments?filter=stream&summary=true&access_token=yourtoken
>> For Comment Counts without their replies:
https://graph.facebook.com/80329313253_10153617216088254/comments?filter=toplevel&summary=true&access_token=yourtoken
Note: The above urls return a json object having two members (data array: which will show you the comment data, summary object: this will include a field showing total_counts)
It took long time for me to figure out that the summary is shown after all the comments array. Hope this answers your question.
I'm not sure if I understand the question entirely, but are you looking for a total number of Facebook comments for a given post? If so, this works:
https://graph.facebook.com/POST_ID/comments?summary=true&access_token=XXX
After all the comment id's, comment likes, etc there should be this summary:
summary: {
order: "chronological",
total_count: NUMBER
}
It returns the same json, because you request for a LIST of comments.
If you just want the summary, you have to avoid any pagination with the limit-parameter. try this:
graph.facebook.com/10151579052696276/comments/?filter=stream&summary=true&limit=0
in php i used this syntax:
$url="http://graph.facebook.com/?fields=og_object{comments.limit(0).summary(total_count)&10151579052696276";
$FB_Request = file_get_contents($url);