Let's say I have model of posts that belongs to a user. A user has many posts.
Is there a fast and simple way to fetch the latest posts created, but maximum one per user? So even if user A posted the 5 latest post, only the latest is returned, followed by user B's post.
Possible without adding manual logic?
Post.select('DISTINCT posts.*').group(:user_id).order('created_at desc')
The group method will only return one record per group.
Post.group(:user_id)
Update
You can't control which one you get from each group this way but it appears to use the latest one created in the database.
Related
I am running a website, whose community is powered by Disqus. I would like to create user profile pages, where the page would display the particular user's most recent activity, but only for my particular site (forum, in Disqus' terminology).
I ran through the entire API documentation, but I could not find a way that would allow me to filter by both user, and forum. I would be able to grab either the entire list of posts for a given forum, or the one from a particular user.
In every API call, there is a mysterious query paramater, where I tried to plug a series of filters, but none of them worked.
Is there something that I could be missing?
It's not that obvious, but you can use the query param as a filter for users. Try something like this:
https://disqus.com/api/3.0/forums/listPosts.json?forum={SHORTNAME}&query=user:{USERNAME}&api_key={YOUR_API_KEY}
Does anyone know how to detect deleted posts in using the Disqus API?
I'm syncrhonizing posts from Disqus using the forums.listPosts method of the API.
The listPosts method does not update the date of a deleted post, so when retrieving posts incrementaly using the since parameter, deleted posts are never retrieved again, thus I cannot delete them (They have an isDeleted attribute).
Any idea, besides brute force, on how to obtain deleted post when they're deleted?
Thanks!
There is no way to sort data by the date it was modified, so there's no direct way to get comments that have been most recently deleted.
About the only option is to occasionally page through all the deleted comments on the site (by only using the "include=deleted" parameter) and update any comments that have changed states the last time they were added to your database.
Lets asume I fetch recent user media for a tag... And that I am able of storing in a database the information that it is returned to me by the API.
The media ids are something like [0-9]+_[0-9]+, and lets asume that one day later, I want to fetch only new data, so I order the media, that I stored in my DB, by instagram's created time, then I select the one that its the newest and grab its id something like '121231232213123_12312312312'.
Then I use that Id as the max_id attribute for the API endpoint https://api.instagram.com/v1/tags/{tag_name}/media/recent, I would assume, that I would get new user_media or an empty array if no one had upload anything.
The thing is that I receive all the same data, its like if it not filtering my results nor using the max_id.
is this correct behavior or should I do something else?
thanks,
ps: I posted this same issue also on google groups:
https://groups.google.com/forum/?fromgroups#!topic/instagram-api-developers/QyjCORkjr3I
I found 2 tips, that can be useful for you:
You should use min_id, in order to get new media. max_id will return photos, older that the one with this id.
It's better to use live API in order to update your DB with new photos dynamically.
UPDATE:
Instagram live API is deprecated now. However you can now use webhooks subscription system which is very similar to facebook. Details can be found in this answer.
I'm trying to query Picasa Web Albums to pull album/photo data (obviously!) however initially I only need to pull the first 4 photos. Is there any way to limit a particular field or specify the items per page?
I've already accomplished something similar with Facebook's Graph API however I'm unable to find anything similar for Picasa. The only items I can find related to limiting the response is specifying which fields, but nothing related to the number of rows.
Use max-results argument. See doc here.
https://developers.google.com/picasa-web/docs/2.0/reference#Parameters
Let's say user A follows user B, and B follows A. I want to know the exact date A started following B and viceversa.
Is this information stored on twitter? Can I retrieve it using the API?
To clear out: The point of this question is finding a way to know who followed who first.
(I'm assuming both A and B deleted the notification e-mails)
No Ignacio, you can't. You just can know who follows who but not the date the follow started.
Looking at the API, there's is no way, there are two calls to get the followers:
User Methods/statuses/followers
and
Social Graph Methods/followers/ids
Neither of them returns dates or even a serial that would let you see who started following first. Really, there's no indication that twitter is internally storing this information, neither in the API nor Twitter's web interface.
This is a very old question, but perhaps some might be interested to know that while you cannot get the date at which someone started following, you can at least infer an "earliest possible following date" from the fact that the list of followers is ordered according to date, and the fact that follower objects come with a created_at timestamp.
Here's a Python function for calculating an "earliest possible following date": https://github.com/BernhardClemm/twitter-follow-dates
Of course Twitter stores it, because Twitter sorts followers and following lists by the date ;)
It is possible to do this, but impractical. When you call the followers API you can page the results. Each returned object contains next_cursor and prev_cursor items. These refer to the first and last records in the next and previous pages. These values are time based and can be used to calculate the time that the respective users followed you.
It follows that, if you set the page size to 1, you can walk through the list of follower IDs one at a time and the next_cursor value will allow you to derive the follow time for the next record.
This is reasonably simple to implement, however, in practice, you'll very quickly hit Twitter's API rate limit.