I am trying to integrate Facebook API to my web app. I want to check approximately when the user joined Facebook by querying earliest comment like following:
SELECT text, time FROM comment WHERE fromid= me() ORDER BY time ASC LIMIT 1
However, I got error saying:
"message": "Your statement is not indexable. The WHERE clause must contain an indexable column.
How can I fix this issue?
Thank you.
The comment table is for fb:comments, so you need to use the proper table first. This would be the status table. http://developers.facebook.com/docs/reference/fql/status.
SELECT status_id, message, time FROM status WHERE uid=me() ORDER BY time ASC LIMIT 1
But
What if the first post is from another user?
Then we should use the stream table. The first item in the news feed, should theoretically be after the date of joining (why show items before?) This is assuming the API holds all the data for the news feed.
So this will involve playing with streams, filter_keys and created_time
http://developers.facebook.com/docs/reference/fql/stream_filter
http://developers.facebook.com/docs/reference/fql/stream
A FQL query with a WHERE clause must include an indexable column, as shown in the docs for the table (they're now marked with a star, & shown in the Supported Base Where Clauses section).
fromid is not an indexable column so your WHERE clause can't be just a condition on this column.
I don't think it's possible to discover when a user joined Facebook via the Graph API or FQL; there's no property of the FQL User table that gives this, & the Graph API User schema is pretty close to the User table.
Related
I want to create an articles application using serverless (AWS Lambda + DynamoDB + S3 for hosting the FE).
I have some questions regarding the "1 table approach".
The actions I want to follow:
Get latest (6) articles sorted by date
Get an article by id
Get the prev/next article relative to the article opened (based on creation date)
Get related articles by tags
Get comments by article
I have created an initial spreadsheet for the information:
The first problem I have is that for action nr. 1, I cannot get all the articles based on date, I've added the SK for articles as a date, but because the PK has separate articles, each with its id: article-1, article-2.. and so on, I don't know how to fetch all the articles only by SK.
I then tried creating a LSI , but then I noticed that the LSI needs to have the PK the same as the table, so I can select based on LSI type = 'ARTICLE', but I still cannot selected them ordered by date (entities_sort value)
I know AWS says its good for PK to be unique, but then how do you group the data in this case?
I've created a GSI
This helps me get articles by type(GSI2PK)='ARTICLE' sorted by entities_sort (GSI2SK), but isn't there a better way of achieving this? Having your articles as a PK in a table, but somehow still being able to get them sorted by date?
Having GSI1PK, GSI1SK this way - I can get all the comments for an article using reverse lookup, so thats good.
But I still also don't know how to implement number 3. Get the prev/next article relative to the article opened (based on creation date): getting an article by id, check its creation date(entities_sort), then somehow get the next article before and after based on that creation date (entities_sort), is there a function in DynamoDB that can do this for me?
In my approach I try to query/process as few items as possible so I don't want to use filter functions, rather partition my information.
My question is, how should I achieve 1 and 3? And isn't creating 2 GSI's for such few actions overkill?
What is the pattern to have articles on a PK, unique with ids, but still being able to get them sorted by creation date?
Thank you
So what I've ended up doing is:
My access patterns in detail are:
Get any Article by Id (for edit/delete)
Get any Comment by Id (for edit/delete)
Get any Tag by Id (for edit/delete)
Get all Articles ordered by date
Get all the Tags of an Article
Get all comments for an article, sorted by date
Get all Articles that have a specific tag, ordered by date (because I want to show only the last 3 ones)
This is the way I've implemented my model, and I can get all the informations needed.
Also, all my data is partitioned and the queries are really efficient, I always get exactly what I need and the ScannedDocuments value is always the number or returned objects.
The Global Secondary Index helps me query by Article Id and I get, all the comments and tags of that Article.
I've solved the many-to-many between Tags and Articles by a new record in the end:
tag_id, article_date, arct_id, tag_id
So, if I want all articles that have a specific tag sorted by date I can query the PK of the table and sort by SK. If I want to get a single Tag (for edit/delete) I can use the GSI by: article_id, tag_id .. and I get the relation between them.
For getting all Articles sorted by date, i query PK: ARTICLE and an option condition if I want to get only the ones after a date or not I can condition the SK.
For all the comments and tags of an Article I can use the GSI with : article_link_pk: article_id and I get all comments and tags. If I want only comments I can say article_link_pk: article_id and article_link_sk: begins_with(article_link_sk, '2020') in this way I get only comments, without tags.
The data model in NoSQL Developer looks like this:
The GSI reverse lookup looks like this:
It's been a journey, but I feel like I finally got a grasp on how to do data modelling in DynamoDB
Even the basic query - GET /fql?q=SELECT name FROM user WHERE uid = me() is giving the following error -
"message": "Your statement is not indexable. The WHERE clause must contain an indexable column. Such columns are marked with * in the tables linked from http://developers.facebook.com/docs/reference/fql ",
? For FQL just choose FQL Query instead of Graph API in the top of the page.
I would like to query earliest posts of a Facebook user using FQL or Graph API. The big issue is by default, Facebook limit return items, which are ordered by descending time.
I know I can limit my query by until, but I don't know what date to put in, because I have no idea when my user become Facebook member. I have to do search like:
find post until Jan 2006
if null, then find post until Jan 2007
if null, then find post until Jan 2008
....
which I hate so much.
Is there a smarter way to find out earliest posts by user?
First off, it's near impossible to have an all encompassing program that determines when a user joined Facebook, to put it quite bluntly. I know from your past questions, you have been trying but many have tried before you, it's not possible.
For example what happens if no one decides to write anything on my wall from the date I joined to 1 year after? That indicator becomes pretty inaccurate now does it?
Anything smarter is based on assumptions that may or may not hold true.
e.g.
Assumption 1: Every Facebook user would publish a post on or near when they joined
this give an initial guess based on A1
Assumptions 2: Given A1, any post by a friend on a user's wall that is posted before the unix time returned by A1 will be earlier in date
this will always be true as long as A1 holds.
All of this falls when there is a year between actual activity and join date.
You can minimize the set returned by calling less data per item and more items overall
/me/feed?fields=created_time&limit=200
Then you page until there is no next paging parameter left.
If you are indeed trying to find when did a user join Facebook, I agree with phwd's answer.
The best way I have been able to find out (which is also cheaper than having to reiterate through tons of posts) is accessing the earliest "profile pictures" of the user. This is making the assumption that a user would post a profile picture soon after creating their account.
Once you can get access to "Profile Pictures" album, you might be able to use created_time field for the album (or sort Profile Pictures by created_time for individual photos).
Even if the earliest photo was deleted, what are the chances that the user stays without any profile picture for a long time?
Reference:
https://developers.facebook.com/docs/graph-api/reference/v2.0/album
Two questions regarding tracking shared links:
I have a URL and I want to get a list of public shares for that URL. I found this was answered a couple of times here on stackoverflow claiming it's impossible, but I don't understand why this is not allowed. If I can query public posts for given search keywords, like: https://graph.facebook.com/search?q=watermelon&type=post, then why can't I use URLs as my search query? Or is there a way to do this that I just missed somehow?
Let's say I have a link_id for a shared URL in the "link" FQL table. How can I find reshares of that link? (As possible in the Facebook website.)
As an attempt to find middle ground between the above 2 problems, I tried to perform this FQL query:
SELECT link_id, owner, title FROM link WHERE url="<url>" AND (
owner = me() OR owner IN (SELECT uid2 FROM friend WHERE uid1 = me())
)
But this failed, with error:
<error_response xmlns="http://api.facebook.com/1.0/">
<error_code>1</error_code>
<error_msg>An unknown error occurred</error_msg>
</error_response>
I don't think that it is possible to search based on URL when doing an FQL query on the link table because the url column is not indexable. The indexable columns are marked with a star on the Facebook FQL link reference.
Because the only indexable columns are link_id and owner_id, I do not think you can use FQL on this table to solve your problem. You could potentially load all available links into your application and then parse through them, but that API call can take a long time.
If you want to just search public posts, you could try putting the url directly into the query area of your public graph search. For example, if I wanted to search for references to www.google.com:
GET https://graph.facebook.com/search?q=www.google.com&type=post
I'm currently trying to query the facebook api to retrieve some data via batch-requests with two fql queries.
One of the queries fetches a set of album ids in the form of:
Select aid FROM album WHERE ...
While the other one tries to retrieve photos for the found albums:
SELECT ... FROM photo WHERE aid IN ({result=album_ids:$.*.aid})
Where 'album_ids' is the name of the first query.
Most of the time this works perfectly but sometimes a album comes along with an aid containing a '_' - Which would be perfectly fine since the documentation specifies the aid as string.
However the jsonpath in the second query does not quote the ids according to the facebook api:
Parser error: unexpected '_xxxxx' at position xx
...
SELECT ... FROM photo WHERE aid IN (10000xxxxxxxxxx_xxxxx)
The json result for the first query clearly has them quoted:
[{\"aid\":\"xxxxxxxxxxxxxxxxxxx\"},{\"aid\":\"10000xxxxxxxxxx_xxxxx\"},...]
Am i missing something here or does facebook wrongly skip to quote the ids in the second query even though they are clearly strings.
As far as i see in the facebook-api and jsonpath specs this should be working.
Or is there a work-around to get this to behave as expected? (Except of doing the quoting client-side and with two seperate requests).
Right now i'm trying to change my query as suggested here: Quoting/escaping jsonpath elements for in clause of dependent fql queries
But maybe there is a way without completely re-structuring the queries itself.