FQL查询采用Android获得的Facebook好友生日在接下来的30天内 [英] FQL Query to get Facebook Friends Birthdays in next 30 days using Android

查看:201
本文介绍了FQL查询采用Android获得的Facebook好友生日在接下来的30天内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的Andr​​oid应用程序,其中我是的使用下面code当月的那些生日获取的好友列表:

I am writing Android Application, in which i am fetching list of friends those birthdays in current month by using below code:

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";

但现在我想为获取的Facebook好友名单中接下来的30天内的生日,我知道的的Java code到接下来的30天内通过使用当前日期获取象下面这样:

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:

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

我知道Python的查询来获取生日在接下来的30天内来了,但我不知道是什么codeI需要在Java中使用,如果可能的话,请更换下面查询写在Java中对我来说: -

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:-

 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");

所以在这里我只是想取代蟒蛇code到Java code

推荐答案

好吧,首先,请务必索要 friends_birthday 许可,没有它,你不能让你的朋友的生日日期。

Well, first of all, make sure to ask for friends_birthday permission, without it you can't get your friends birthday dates.

如果您不熟悉的图形API资源管理器,你应该 - 你可以测试FQL查询来发现问题。

If you are not familiar with the Graph API Explorer, you should - you can test FQL queries to find problems.

点击获取访问令牌,并在老友记数据权限检查friends_birthday
你是好去测试查询。

Click the "Get Access Token" and in "Friends Data Permissions" check the "friends_birthday" and you are good to go testing the query.

二,所有的生日都存储与实际出生年份,在FQL查询,以便要求今天上面总是返回什么。
修理的日期 - 你可以实际选择,今年它的生日的一部分,并像这样:

Second, all the birthdays are stored with the actual birth year, so asking for above today in FQL query will always return nothing. 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' 

在这里,问题来了:

选择的字段不是用户表的一部分,你不能排序,或者甚至可以使用WHERE就可以了。
我的猜测是,你必须让你的所有朋友的生日和使用Java来过滤数据 - 这应该是很容易,因为在自定义所选字段的日期有2013,而不是真正的年度

The selected field is not part of the user table, and you can't sort by it, or even use WHERE on it. 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.

随意<一个href=\"https://developers.facebook.com/tools/explorer?fql=SELECT%20name%2C%20birthday%2C%20birthday_date%2C%20concat%28substr%28birthday_date%2C0%2C6%29%2C%222013%22%29%20FROM%20user%20%0AWHERE%20uid%20in%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me%28%29%29%20AND%20birthday_date%20!%3D%20%27null%27\">Test在FQL此链接。

编辑#1

我想的东西清晰,原始查询要转换不会

I want to be clear on something, the original query you wish to convert will not

获取的Facebook好友名单中接下来的30天内的生日

fetch list of Facebook friends those birthdays in next 30 days

当在我看到它返回所有的朋友,在同月2日给出的之间的生日查询手动替换值。
它没有找到所有谁在接下来的30天生日的朋友。

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. It does not find the all the friends who has a birthday in the next 30 days.

编辑#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')

这应该成为更容易打开名册,并从今天起过滤今天之前的那些,也没有超过30天 - 这是我能想到的最好的办法

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.

编辑#3
其实我可以利用过滤从编辑#2相同的查询来获取今天毕竟那些由它下令:

EDIT #3 I can actually filter using the same query from edit #2 to get all the ones after today, ordered by it:

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

如果你想用10来限制:

And if you want to limit by 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

编辑#4

更简单,如果你计算的日期在Java中,并将它传递到查询

Much more simple if you calculate the dates in Java and pass it to the 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 > '02/23/2013'
    AND birthday_date < '04/24/2013'
ORDER BY birthday_date ASC

编辑#5

一些Java code:

Some Java code:

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";

我没有测试过,没有安装Java的: - )

I have not tested it, don't have Java installed :-)

这篇关于FQL查询采用Android获得的Facebook好友生日在接下来的30天内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆