I'm trying to make a custom-feed from my companies Facebook page to our website. I query the Graph API of Facebook to get this information.
Facebook changed the API a while ago to not include like counts in the normal page query. In the documentation it says to add summary=1 to get the total likes. My query does not return the total_count tho when I query it.
I am omitting my acces_token in the queries because I'm using the API Explorer.
Query I use to get posts:
Raafh/posts?limit=4
trying to add summary=1 does nothing with the query.
I can however do another query which will return the likes and the total count, but not the post info so I can't use it, or I have to use two queries.
Raafh/posts?fields=likes.summary(1).limit(1)
This posts the last like + the total_count.
How can I combine these two in one query?
You can add required fields in comma separated format to get post data like shown in example below.
Raafh/posts?fields=likes.summary(1).limit(1),id,message,from,picture,link,name,caption,description
Related
I'm trying to query for a specific purchase order using the "PurchaseOrderNumber" field, however regardless of what value I provide, all PurchaseOrders are returned.
I've replicated the exact same code except swapped out for Invoices and the querying of "InvoiceNumber" works fine, just not PurchaseOrders.
Here's the URL I'm calling:
https://api.xero.com/api.xro/2.0/PurchaseOrders?where=PurchaseOrderNumber%3D%3D%22PO-0007%22
You can query purchase orders both by Id and Purchase order number.
So your request would look something like
api.xero.com/api.xro/2.0/PurchaseOrders/PO-0001
PO-0001 can be substituted by the actual id as well.
Look at xero documentation here, and the optional parameters section.
Hope this helps.
I have a screen that looks very much like facebook timeline
users can view posts of other users etc.
to get these posts i do something like
select user.id,user.name,posts.title,posts.body from posts left join users;
now data i need to collect is "Who saw this post" .
is there any elegant way to do it ?
right now all what i can think of is every time i fetch posts. i loop over them, then collect all ids of posts that the query returned and then push in another table
user_views [pk:user_id+postId]
userId,postId
1 , 1
Then when i'm fetching posts next time i can do count of user_views.
select *,count(user_views.id) from posts join user_views on post_id = post.id
but this sound like a lot of work for each VIEW, specially that most probably user will see a most multiple times,
is there any known patterns for such need ?
This is a design question and the answer really depends on your needs.
If you want to know exactly who viewed what post and how many times, then you need to collect the data on user - post level.
However, you may decide that you do not really care who viewed which post how many times, you just want to know how many times a post was viewed. In this case you may only have a table with post id and view count fields and you just increment the view count every time a post is being viewed.
Obviously, you can apply a mixed approach and have a detailed user - post table (perhaps even with timestamp) and have an aggregate table with post id and view count fields. The detailed table can be used to analyse your user's behaviour in a greater detail, or present them a track of their own activities, while your aggretage table can be used to quickly fetch overall view counts for a post. The aggregate table can be updated by a trigger.
I am fetching data using blogger post API.
https://www.googleapis.com/blogger/v3/blogs/blogId/posts
The results are coming in the newest to oldest format with pagination.I need to fetch with oldest to newest because i need the newest post's time to fetch the data in the next call for the new posts.
How can I use the API with parameters.Currently, i am using the following api call
https://www.googleapis.com/blogger/v3/blogs/posts?startDate2015-10-15T00:00:00+00:00&key=$key
Posts: list only supports ordering by published or updated, not the direction.
orderBy string Sort order applied to results.
Acceptable values are: "published": Order by the date the post was
published "updated": Order by the date the post was last updated
I would recommend you sort them yourself after you get the results back from Google.
I've used the old Facebook SDK where I could do FQL-queries. I want to fetch all nearby places that also has a page attached. And with those results, I want as many columns as possible.
I want to rewrite this function so I can do the same but with the latest Facebook SDK 2.3.
The old way:
SELECT name, type, page_id, hours, categories, about, bio, description, general_info, location, checkins, fan_count, phone, pic_big, website FROM page WHERE page_id IN(SELECT page_id FROM place WHERE distance(latitude, longitude, '37.76', '-122.427') < 1000)
But this doesnt work so well with the new SDK. I've tried the search-method and tried to write different types of queries (in the 'q' parameter) but nothing gets close to this.
As you can see, I want as many columns about the pages as possible.
The closest I've come is this far: https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=search%3Fq%3Dcoffee%26type%3Dpage%26center%3D37.76%2C-122.427%26distance%3D1000&
Does anyone know how I should think/do in order to get this data in the new way?
Have a look at
https://developers.facebook.com/docs/graph-api/reference/page#Reading
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#fields
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#search
You can specify the desired result fields according to the fields which are available for the respective object.
For example
/search?q=coffee&type=place¢er=37.76,-122.427&distance=1000&fields=id,name,hours,category,category_list,about,bio,description,general_info,location,talking_about_count,were_here_count,likes,phone,cover,website
Try it
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=search%3Fq%3Dcoffee%26type%3Dplace%26center%3D37.76%2C-122.427%26distance%3D1000%26fields%3Did%2Cname%2Chours%2Ccategory%2Ccategory_list%2Cabout%2Cbio%2Cdescription%2Cgeneral_info%2Clocation%2Ctalking_about_count%2Cwere_here_count%2Clikes%2Cphone%2Ccover%2Cwebsite
Keep in mind that the fieldnames are not the same from FQl to Graph API.
I am working on a social network website project. I have created database and everything.
The posts table has a preference column which stores the preference value according to the likes and comments that a post gets from the users and also the time at which the post is created.
To retrieve posts for a user's home page from the posts table, I am running a query using joins which sorts using preference column .
Now, suppose I retrieve 10 posts for a user to be shown on the posts table and user scrolls down and one more request is made from the user to retrieve next 10 posts to the server.
If in between of those requests few other users creates a new post or preference value of posts in the database changes in the between, and now if I the second request is run on the server, all the posts will be resorted for the second request (i.e. to show next 10 posts) but since the database is updated , this means in the second request there will be many chances that few of earlier 10 posts are retrieved along in the second request.
I want to know how to avoid these duplicate requests.
How facebook or any other social network solves this problem at the backend when their database is dynamic.
I would rather avoid such unreliable way of sorting at all.
As a user, I'd rather quit that service. Frankly, I hate such too smart a service which decides which posts I have to see and which not. And even dynamically ordered on top of that.
Make it ordered by date, by tags of interest, by something sensible, reliable and constant.
In your script store a record of the rows id returned.
For example, using a basic limit and just storing the latest id when the first select is done, and using the page number to determine the limit of records to return.
SELECT id, somefield
FROM SomeTable
WHERE id < $SOMESTOREDVALUE
LIMIT $PAGENUMBERTIMESTEN, 10
or storing the latest id after each page is returned (which you will need to store each time this is run)
SELECT id, somefield
FROM SomeTable
WHERE id < $SOMESTOREDVALUE
LIMIT 0, 10
If you store the time & date when the user first makes a request in a session, you could use that to filter the posts table.
So your SQL for the second page of results would be along the lines of
SELECT <some fields> FROM <sometables>
WHERE DatePosted <= $timefirstseen LIMIT 10, 10
Where $timefirstseen was loaded from the session variable. This will restrict your results to only posts that existed when the users visit started.
You would of course need to include a feature to allow the user to clear the session or do that automatically when they revisit their homepage to make sure they got to see the new posts eventually!