I have two tables one for post and one for likes.
Post table stores all the post information.
Likes table has 3 columns
id,
post_id
user_id
Now I need help to figure out how to get total number of likes of each post through supabase query. I am using react for frontend.
const { data, error } = await supabase
.from('feedback')
.select()
.order('created_on', { ascending: false });
Have you created a supabase client for your project?
if not follow this Doc
https://github.com/supabase/supabase-js
Then import the client into the file you want to retrieve data.
you have left .select() empty. select can be combined with modifiers
for example, you can...
const { data, error } = await supabase
.from('feedback')
.select(`post_id`)`
DOCs for reference: https://supabase.com/docs/reference/javascript/select
You may want to have your likes and post ids on the same table to save yourself from issues. Maybe add another column.
id, post_id user_id, post_likes
however your question is very broad hope this can point you in some of the right directions.
Related
I am trying to retrieve a list of user ids that have read access to a specific record from the Salesforce REST API.
I have been able to use the UserRecordAccess SObject and the following SOQL query to check if a single user has access to the record.
SELECT RecordId, HasReadAccess FROM UserRecordAccess WHERE RecordId = '{insert record id}' AND UserId = '{insert user id}' AND HasReadAccess = true
However, a limitation of this query is that UserRecordAccess does not let you "SELECT" the UserId.
e.g
SELECT RecordId, UserId FROM UserRecordAccess
Is there another way to get this information?
I want to avoid sending a request for every single user per record.
Any help would be greatly appreciated.
I have been experimenting with Supabase recently and trying to make a twitter like 'replying to #user' comment feature.
So I have a database ERD attached below for reference, As you can see each comment has a userid and also a 'replyingTo' which also stores the userid of the comment which is being replied to.
Now I'm able to query individually between these two tables, So I can get the user of comment along with the comment very easily but however, When I'm trying to fetch the user profile of the comment creator and the profile of replyingTo, I get the following error -
Could not embed because more than one relationship was found for 'Comments' and 'profiles'
I'm not too experienced at PostgreSQL so I'm not sure how to do something of this scope, This is the following code I'm using currently which is giving me the error I have described above.
const { data, error } = await supabase
.from('Comments')
.select('ReplyingTo, profiles:profiles(id), profiles:profiles(id)')
.eq('commentid', cmtid)
My expected outcome is to get the comment, the user profile who created the comment and also the profile of the user who is receiving a reply.
Thank you for your time and patience.
As the error says, the problem is that you have two relationships between profiles and Comments. For this case, you'd need to disambiguate(which foreign key column you want to use for the join) as specified in the PostgREST docs. For the supabase js client, it should be like:
const { data, error } = await supabase
.from('Comments')
.select('ReplyingTo, profiles1:profiles!userid(*), profiles2:profiles!ReplyingTo(*)')
.eq('commentid', cmtid)
Hi i have written a query by which i can fetch posts,actor_id,comments and other columns required from stream table. But i want to fetch user's name also along with actor id and other columns in a single query.
My queries is :
select message,created_time,actor_id,attachment,comments,created_time,impressions,likes,message,message_tags,place,share_count from stream where source_id in (any_page_id)
I want to add user's name also from user table along with this list of columns i am fetching from stream table in a single query so that i can handle it in a single json file. .
Also in comments we will get several user's id with comments as from_id. Can we get username for this from_id also. Is this possible, i know we cannot use join in FQL. Or i am missing something or in a wrong approach. Please help me out. Thanks in advance.
Updated
Now i am able to get actor_id and other fields of the post together along with user's name at the end in the same json using multi-query. Something similar to :
fql?q={"query1":"select+message,created_time,actor_id,attachment,comments,created_time,impressions,likes,message,message_tags,place,share_count+from+stream+where+source_id+in(any_page_id)","query2":"select uid,name from user where uid in (*#query1* "}
But now i am not able to get the user's name and user's id who are there in the comments of the post in the same json.
I'm trying to get demographics for fans of a page on Facebook - mostly country and city, but age and gender as secondary.
The primary way to do it is using FQL and doing a query in the insights table. Like so:
FB.api({
method: 'fql.query',
query: "SELECT metric, value FROM insights WHERE object_id='288162265211' AND metric='page_fans_city' AND end_time=end_time_date('2011-04-16') AND period=period('lifetime')"
}, callback);
The problem with this, however, is that the table returns a maximum of 19 records only, both for the country and the city stats. The response for a page I'm testing is as such:
[
{
"metric": "page_fans_city",
"value": {
"dallas": "12345",
"atlanta": "12340",
(...)
"miami": "12300"
}
}
]
So I'd like to know if there's any alternative to that -- to get demographics of the current fans of a page (no snapshot necessary).
Things I've tried:
Using LIMIT and OFFSET on the query do nothing (other than, sometimes, give me an empty list).
One alternative that has been discussed in the past is to use the "/members" method from the Graph API (more here) to get a list of all users, and then parse through that list. That simply doesn't work - a method exists, and it may have worked in the past, but it's not valid anymore (disabled?).
Request:
https://graph.facebook.com/platform/members?access_token=...
Response:
{"error":
{
"type":"OAuthException",
"message":"(#604) 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 "
}}
Other solution was to do a query to the page_fan table and filtering by page_id. This doesn't work, either; it may have worked in the past, but now it says that the page_id column is not indexable therefore it cannot be used (same error as above, which leads me to believe /members uses the same internal API that has been disabled). Page_fan query is only useful to check if individual users are fans of a page.
There's also the like table, but that's only useful for Facebook items (like posts, photos, links, etc), and not Facebook Pages.
Going to the insights website about the Page, you can see the data in some nice graphs and tables, and download an Excel/CSV spreadsheet with the historic demographics data... however, it also limits the data to 19 entries (sometimes 20 with a few holes in there as cities trade top positions though).
Any other hint on how to get that data? I'd either like the insights query with more results, or at least a way to get all the page fans so I could do the location query myself later (even if the page I want to get it from has almost 5 million fans... gulp).
The data pipeline for this metric is currently limited to 20 items. This is a popular feature request and something Facebook hopes to improve soon.
I'm looking for a very simple "hello world" type of example that will help me understand how to use JavaScript to retrieve the Insight data for my domain.
I want to return the total number of Likes (domain_like_adds) for the day on my website, but I'm not sure how to go about it. The Facebook documentation has me running in circles.
Thanks for your help!
See this page for more information on how to define your query:
http://developers.facebook.com/docs/reference/fql/insights/
Here's the basic query and facebook JS API query with callback function:
var insight_domain = "http://www.mydomain.com";
var insight_query = "SELECT metric, value FROM insights where metric="domain_like_adds" AND end_time=end_time_date('2011-04-06') AND period=period('day') AND object_id in (select id from object_url where url ='{0}')";
var query = FB.Data.query(insight_query, insight_domain);
query.wait(function(data) {
//process your insight data here
});