简体   繁体   English

FQL查询使用Android在未来30天内获得Facebook好友生日

[英]FQL Query to get Facebook Friends Birthdays in next 30 days using Android

I am writing Android Application, in which i am fetching list of friends those birthdays in current month by using below code: 我正在编写Android应用程序,其中我通过使用以下代码获取当月那些生日朋友列表

Calendar c = Calendar.getInstance();
int month = c.get(Calendar.MONTH) + 1;
String query = "select name, birthday, uid, pic_square from user 
where  (substr(birthday_date, 0, 2) =" + month +") AND uid IN 
(SELECT uid2 FROM friend WHERE uid1 = me()) order by birthday_date ASC";

but now i want to fetch list of facebook friends those birthdays in next 30 days , i know the java code to get next 30 days by using current date like below: 但现在我想在接下来的30天内获取Facebook朋友的那些生日列表 ,我知道使用下面的当前日期获得接下来30天java代码

    Date today = new Date();
    Calendar cal = new GregorianCalendar();
    cal.setTime(today);
    cal.add(Calendar.DAY_OF_MONTH, +30);
    Date today30 = cal.getTime();

I know Python query to fetch Birthdays coming in next 30 days, but i don't know what code i need to use in Java, if possible so please replace write below query in Java for me:- 我知道Python查询将在未来30天内获取生日,但我不知道我需要在Java中使用什么代码,如果可能的话请为我替换以下用Java编写的查询: -

 query = "SELECT username FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND (substr(birthday_date, 0, 2) = {0} AND substr(birthday_date, 3, 5) >= {1} AND substr(birthday_date, 3, 5) <= {2})").format(today.strftime("%m"), today.strftime("%d"), today30.strftime("%d");

So here i just want to replace python code to java code 所以在这里我只想将python代码替换为java代码

Well, first of all, make sure to ask for friends_birthday permission, without it you can't get your friends birthday dates. 好吧,首先,确保要求friends_birthday权限,没有它你就不能得到朋友的生日日期。

If you are not familiar with the Graph API Explorer , you should - you can test FQL queries to find problems. 如果您不熟悉Graph API Explorer ,则应该 - 您可以测试FQL查询以查找问题。

Click the "Get Access Token" and in "Friends Data Permissions" check the "friends_birthday" and you are good to go testing the query. 单击“获取访问令牌”,然后在“朋友数据权限”中选中“friends_birthday”,您就可以开始测试查询了。

Second, all the birthdays are stored with the actual birth year, so asking for above today in FQL query will always return nothing. 其次,所有的生日都与实际的出生年份一起存储,因此above today在FQL查询中要求above today内容总是不返回任何内容。 to "fix" the date - you can actually select a portion of the birthday and this year to it like so: “修复”日期 - 您实际上可以选择生日和今年的一部分,如下所示:

SELECT name, birthday, birthday_date, concat(substr(birthday_date,0,6),"2013") FROM user 
WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) 
AND birthday_date != 'null' 

And here comes the problem: 这就是问题所在:

The selected field is not part of the user table, and you can't sort by it, or even use WHERE on it. 所选字段不是用户表的一部分,您不能按它排序,甚至不能使用WHERE。 My guess is that you have to get all your friends birthday and use JAVA to filter the data - It should be easy since the date in the custom selected field has 2013 instead of the real year. 我的猜测是你必须让所有朋友过生日并使用JAVA来过滤数据 - 这应该很容易,因为自定义选择字段中的日期有2013而不是实际年份。

Feel free to Test the FQL with this link. 随意使用此链接测试 FQL。

EDIT #1 编辑#1

I want to be clear on something, the original query you wish to convert will not 我想明确一些事情,你想要转换的原始查询不会

fetch list of Facebook friends those birthdays in next 30 days 在接下来的30天内获取Facebook朋友的那些生日列表

When replacing the values manually in the query I saw that it returns all friends with birthday between 2 given days in the same month . 当在查询中手动替换值时,我看到它返回所有在同一个月中 2个给定日期之间生日的朋友。 It does not find the all the friends who has a birthday in the next 30 days. 它没有找到所有在接下来的30天内过生日的朋友。

EDIT #2 编辑#2

I have found a way to get all friends with birthday in this month and the next - which is much better the to go over all the friends list. 在这个月和下一个月里,我找到了让所有朋友过生日的方法 - 这比查看所有朋友列表要好得多。

SELECT name, birthday, birthday_date, concat(substr(birthday_date,0,6),"2013") FROM user 
WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) 
    AND birthday_date != 'null' 
    AND (substr(birthday_date,0,2)='02' OR substr(birthday_date,0,2)='03')

This should become much easier to go over the list and filter the ones before today and no more then 30 days from today - this is the best solution I can think of. 这应该变得更容易遍历列表并在今天之前过滤掉那些并且从今天起不超过30天 - 这是我能想到的最佳解决方案。

EDIT #3 I can actually filter using the same query from edit #2 to get all the ones after today, ordered by it: 编辑#3我实际上可以使用编辑#2中的相同查询进行过滤,以获得今天之后的所有查询,按其排序:

SELECT name, birthday, birthday_date, concat(substr(birthday_date,0,6),"2013") FROM user 
WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) 
    AND birthday_date != 'null' 
    AND (substr(birthday_date,0,2)='02' OR substr(birthday_date,0,2)='03')
    AND birthday_date > '02/23/2013'
ORDER BY birthday_date

And if you want to limit by 10: 如果你想限制10:

SELECT name, birthday, birthday_date, concat(substr(birthday_date,0,6),"2013") FROM user 
WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) 
    AND birthday_date != 'null' 
    AND (substr(birthday_date,0,2)='02' OR substr(birthday_date,0,2)='03')
    AND birthday_date > '02/23/2013'
ORDER BY birthday_date
LIMIT 10

Edit #4 编辑#4

Much more simple if you calculate the dates in Java and pass it to the query 如果您在Java中计算日期并将其传递给查询,则会更加简单

SELECT name, birthday, birthday_date FROM user 
WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) 
    AND birthday_date != 'null' 
    AND birthday_date > '02/23/2013'
    AND birthday_date < '04/24/2013'
ORDER BY birthday_date ASC

EDIT #5 编辑#5

Some Java code: 一些Java代码:

Calendar cal = Calendar.getInstance();
Date today = cal.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
String today_formatted = formatter.format(today);
cal.add(Calendar.DATE, 30);
String today_plus30_formatted = formatter.format(cal.getTime());

String query = 
"SELECT name, birthday, birthday_date FROM user 
WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) 
    AND birthday_date != 'null' 
    AND birthday_date > '" + today_formatted + "'
    AND birthday_date < '" + today_plus30_formatted + "'
ORDER BY birthday_date ASC";

I have not tested it, don't have Java installed :-) 我没有测试过,没有安装Java :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM