I am trying to get comment of a fanpage since a given time. But it seems like the since parameter is ignored.
try {
$attachments = array('access_token' => $profile['access_token'], 'since' => strtotime('2013-03-07T18:13:57+0000'));
$comments = $facebook->api("$id/comments", 'GET', $attachments);
print_r($comments);
} catch (FacebookApiException $e) {
error_log($e);
}
IsnĀ“t that possible?
No, since doesn't work with every table. A solution is to use FQL:
SELECT id, time, text
FROM comment
WHERE object_id = POST_ID
AND time > UNIX_TIME
LIMIT 50
OFFSET 0
(replace POST_ID and UNIX_TIME)
You can loop on this query while incrementing the OFFSET by 50.
The first group will give the 50 most recent comments, the second the 50 previous and so on. But each group contains comments ordered in chronological order.
You can stop looping once a query sends less than 50 results.
Related
I unsuccessfully attempted to leverage Java's DerivedQueries but cannot accomplish the required result so I have to manually write a SELECT Statement.
I want to display one single record in my UI. This should be the most recently generated record (which means it has the highest ID Number) associated with a category that we call "ASMS". In other words, look through all the rows that have ASMS#123, find the one that has the highest ID and then return the contents of one column cell.
ASMS: Entries are classified by 11 specific ASMS numbers.
ID: AutoGenerated
PPRECORD: New entries being inserted each day
I hope the image makes more sense.
//RETURN ONLY THE LATEST RECORD
//https://besterdev-api.apps.pcfepg3mi.gm.com/api/v1/pprecords/latest/{asmsnumber}
#RequestMapping("/pprecords/latest/{asmsNumber}")
public List<Optional<PriorityProgressEntity>> getLatestRecord(#PathVariable(value = "asmsNumber") String asmsNumber) {
List<Optional<PriorityProgressEntity>> asms_number = priorityprogressrepo.findFirst1ByAsmsNumber(asmsNumber);
return asms_number;}
The ReactJS FE makes an AXIOS.get and I can retrieve all the records associated with the ASMS, but I do not have the skill to display only JSON object that has the highest ID value. I'm happy to do this in the FE also.
I tried Derived Queries. .findFirst1ByAsmsNumber(asmsNumber) does not consider the highest ID number.
Try this:
SELECT pprecord FROM YourTable WHERE id =
(SELECT MAX(id) FROM YourTable WHERE asms = '188660')
Explanation:
First line select pprecord, second line select the id
I'll improve the answer if any additional question. Upvotes and acceptions are appreciated~
I have been having a very unusual behavior when using Realm to insert and read/query data. Here is what is happening to be precise:
Initial Status
When I start to insert data to the database, everything works fine. I have the following code to handle autoIncrementingId since I have not found a version of Realm that offers this out of the box!
CashOrder cashOrder = new CashOrder();
realm.beginTransaction();
int lastCashOrderId;
RealmResults<CashOrder> cashOrders = realm.where(CashOrder.class).findAll();
cashOrders.sort("id", Sort.ASCENDING);
if (cashOrders.isEmpty()){
cashOrder.setId("0");
}else{
lastCashOrderId = Integer.parseInt(cashOrders.last().getId());
cashOrder.setId(String.valueOf(lastCashOrderId + 1));
}
//the rest of the code here
//then copyToRealm here;
realm.copyToRealm(cashOrder);
realm.commitTransaction();
The problem
Insertion of data into the database works just fine but the moment the id value reaches 10 - implying 11 items in the table since my id starts at (0), I get a Realm Primary Key Exception which basically complains that I am trying to add an already existing object.
I am explicitly calling realm.copyToRealm(obj) instead of realm.copyToRealmOrUpdate(obj) because that is what I want to do. Updates only are allowed when doing an Edit.
I am stuck here and I can't seem to figure out what is causing this issue!
More information
I am using:
compile 'io.realm:realm-android:0.87.4'
I will truly appreciate your help on this! Thanks in advance!
It's because your ID is a STRING and therefore it's ordered as 1, 10, 2, 3, ... 9.
This means when you evaluate the "next ID" when you had already inserted "10",
lastCashOrderId = Integer.parseInt(cashOrders.last().getId());
lastCashOrderId will be 9, and you'll be inserting 10 again.
Solution: use long id for longs, or re-think your auto-increment IDs (f.ex. use UUID.randomString() or something)
P.S. you should use findAllSorted() instead of findAll().sort() for consistent behavior when you update to the newer Realm versions.
EDIT: please use long newId = realm.where(CashOrder.class).max("age").longValue() + 1; to evaluate the new ID, and do this while you're in a transaction.
I'm recently working with the latest spring-boot-1.2.3.RELEASE, with spring-core 4.1.6, spring-data-commons-1.9.2.RELEASE, spring-data-mongodb-1.6.2.RELEASE.
In my case, I'd written something like this:
java.util.List<Tag> records = new java.util.ArrayList<Tag>();
records.count = tagRepos.countTags(query);
if (LOG.isDebugEnabled()) LOG.debug("[getTags] count -> {}", records.count);
if(records.count > 0){
records.records = tagRepos.findTags(query);
if (LOG.isDebugEnabled()) LOG.debug("[getTags] records -> {}", records.records);
}
return records;
And the result above prints out:
[getTags] count -> 2
[getTags] records -> []
No matter the Query object contains criteria or not, the results both the same.
I'd searched for the same situation for a long time but with no luck. Any one has encounter the same problem? I could figure out the problem is on the MongoTemplate#find method, but I could not work out what is the problem is by the time. Could any one help me out ? Thanks.
After some debug I could figure out the problem is happened on the pagination. I'd set page 1 as the first page, but I found spring-data use index 0 as the first page, causing me always try to fetch the second page contents which is not as my expect. So the code is doing very well, that's a good news.
I am using DynamoDBMapper for a class, let's say "User" (username being the primary key) which has a field on it which says "Status". It is a Hash+Range key table, and everytime a user's status changes (changes are extremely infrequent), we add a new entry to the table alongwith the timestamp (which is the range key). To fetch the current status, this is what I am doing:
DynamoDBQueryExpression expr =
new DynamoDBQueryExpression(new AttributeValue().withS(userName))
.withScanIndexForward(false).withLimit(1);
PaginatedQueryList<User> result =
this.getMapper().query(User.class, expr);
if(result == null || result.size() == 0) {
return null;
}
for(final User user : result) {
System.out.println(user.getStatus());
}
This for some reason, is printing all the statuses a user has had till now. I have set scanIndexForward to false so that it is in descending order and I put limit of 1. I am expecting this to return the latest single entry in the table for that username.
However, when I even look into the wire logs of the same, I see a huge amount of entries being returned, much more than 1. For now, I am using:
final String currentStatus = result.get(0).getStatus();
What I am trying to understand here is, what is whole point of the withLimit clause in this case, or am I doing something wrong?
In March 2013 on the AWS forums a user complained about the same problem.
A representative from Amazon sent him to use the queryPage function.
It seems as if the limit is not preserved for elements but rather a limit on chunk of elements retrieved in a single API call, and the queryPage might help.
You could also look into the pagination loading strategy configuration
Also, you can always open a Github issue for the team.
In my email management system, I am retrieving data from MySQL database into Java netbeans. But it is only showing the data for one person. It should move on to next row on each rs.next(), but it is not seemingly. Following code is written in the "Next" Button, which moves on to the next selection in a JList.
try {
DefaultListModel model = new DefaultListModel();
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/email management system","root", "ok" );
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from inbox,curlogin where inbox.rmail like curlogin.mail;");
String fname="";
list.setSelectedIndex((list.getSelectedIndex()+1));
rs.next();
fname = rs.getString("name");
String sender = rs.getString("First");
String reciever = rs.getString("recipent");
String sub = rs.getString("subject");
String msg = rs.getString("message");
String mail = rs.getString("Email");
Date d = rs.getDate("Date");
Timestamp ls = rs.getTimestamp("Seen");
Time t = rs.getTime("Time");
subject.setText(sub);
message.setText(msg);
date.setText(""+d);
time.setText(""+t);
lseen.setText(""+ls);
email.setText(mail);
// TODO add your handling code here:
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(inbox.class.getName()).log(Level.SEVERE, null, ex);
}
user2642282's answer is technically correct but it is lacking explanation and user2642282 misunderstood what your attempting to do. Your half way to the solution with your code but it requires some changes. Lets start with this:
rs.next()
What your doing here is accessing the result set and normally you would write your code like this to loop through all the returned results:
ResultSet rs = stmt.executeQuery("your SQL statement here");
while (rs.next()) {
fname = rs.getString("name");
//...all your original code here
email.setText(mail);
}
Notice how the code is basically exactly the same as your original code except we added the while loop. Normally this would allow you to write out, display, or store each record (email in this case) returned by the query however you want/ need to do something different. So I'll explain what options I think you have next but first here is a link to the Java Docs that will teach everything you need to know about the above code.
Option 1 - Traditional Way
The way most email desktop app's handle this is simply to load all the emails and store them on the file system. This would mean that you need to change your code to load all emails at certain times. Maybe at startup and then every 60 seconds after that check for new messages (usually you should limit checking to no lower than 5 minutes). Then when a user opens a message you load it from its file. When they press next or previous you simply load in the next or previous email from the file system. So your email app is more of a file reader that parses email files and loads their content into your window. You will need to devise a filing system as well. For example naming and saving the emails as their timestamp making it easy to find the next and previous emails. You will also have to deal with deleted emails.
Option 2 - Easy but Bad Practice
Without having to change your code to much you could track which row from the database you read last and run the SQL query every time the user presses the next or previous buttons. You would use the same code your originally posted but add the following:
Check for when next() returns false meaning there is no next or previous email
Add in a variable that keeps track of the last row you read from in the database
Change your SQL query to only return the next or previous row
Option 3 - Hybrid
You could attempt to change your code to the one I showed you and do a hybrid of option 2. What you would do is track the next and previous 10 rows from the database for example. So lets say you last read from row 50. You would run the code I gave you and save all the emails from row 40 to row 60. You have two options for saving the emails:
File system which creates a bit more work but saves memory.
As objects that could take a lot of memory but is easy and fast.
EDIT - Answer to question from comments
Here is how I imagine your code working using option 2 or 3. Notice that ... means I left out code you already have but would just get in the way of this example:
int lastRowRead = 0; // starts as 0 when the program starts
//...all your original code here
ResultSet rs = stmt.executeQuery("...LIMIT "+ lastRowRead +",20;");
if(rs.next()!=false) {
fname = rs.getString("name");
//...all your original code here
email.setText(mail);
}
This code is for option 3. The int lastRowRead should be a global variable that you can keep track of and change each time you run a query to get more messages. You will need to figure out how to catch errors, for example trying to query a row number that doesn't exist. I won't help you code this because it is a good learning opportunity. NOTE: In case you are not familiar with SQL LIMIT here is another example:
....LIMIT 40, 20;
What this means is go to row 40 in the table and read the next 20 rows. So it will return emails from 40 to 60. So if you want to go the super easy but not at all efficient route your SQL query could have:
...LIMIT 40, 1;
This will only return the row number requested. So all you have to do is track which row you last read from and add or subtract 1 from it and run the query again to get the next or previous email.
You are missing a loop that iterates over the resultset. The call
rs.next()
gives you the first row of your SQL result. Try to loop over the results using until rs.next() returns false
two points:
one: if JList current selected value has not changed, when you click next button , you should change your sql , then you can see one's email one by one. at the end of your sql, you should add
select * from inbox,curlogin where inbox.rmail like curlogin.mail limit #{offset} 1
to fix your sql . the offset is a veriable from 0,1,2,3.... it represents one's email from 1 to N
two: you haven't show some event code about JList after selected value was changed. if it was changed , your should get the selected item, and pass it to your sql to filter person's email. so your sql should accept person's name .