首页 \ 问答 \ 谷歌云消息传递时间(Google cloud messaging time to live)

谷歌云消息传递时间(Google cloud messaging time to live)

我正在开发使用GCM的android应用程序,但是如果用户手机不在线,我想取消消息传递。 有没有办法将生存价值的时间减少到最低限度?


I was developing android application which uses GCM, but I want to cancel message delivery if user phone is not online. Is there any way to decrease time to live value to minimum?


原文:https://stackoverflow.com/questions/19201130
更新时间:2023-09-19 09:09

最满意答案

那么,首先,请务必要求friends_birthday权限,否则无法获得朋友的生日日期。

如果您对Graph API Explorer不熟悉,则应该 - 您可以测试FQL查询以查找问题。

点击“获取访问令牌”,然后在“朋友数据权限”中选中“friends_birthday”,您就可以开始测试查询了。

其次,所有的生日都与实际出生年份一起存储,所以above today在FQL查询中询问above today内容总是不会返回任何结果。 为了“修复”日期 - 你实际上可以选择生日和今年的一部分,如下所示:

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年而不是实际年份。

随意使用此链接测试 FQL。

编辑#1

我想澄清一些事情,你想转换的原始查询不会

在未来30天内获取Facebook朋友的生日列表

当在查询中手动替换值时,我看到它返回了生日在同一个月的两个给定日期之间的所有朋友。 它没有找到所有在未来30天有生日的朋友。

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

这应该会变得更容易在今天之前超过列表并过滤掉这些列表,并且从今天起不超过30天 - 这是我能想到的最佳解决方案。

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

如果你想限制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中的日期并将其传递给查询,则更为简单

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

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


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

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

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

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' 

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

Feel free to Test the FQL with this link.

EDIT #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

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.

EDIT #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.

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

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

Edit #4

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

EDIT #5

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

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

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。