2013-03-13 19 views
0

我想知道是否有人听说有关从facebook的android获得更新facebook的sdk。在我的Android应用程序接收Facebook更新

我希望在用户收到消息 或用户收到类似请求或好友请求时收到通知。

你知道做这件事的最小可能吗? 我不想在我的应用程序中阅读消息或喜欢,我只想通知:用户配置文件上的新活动,以便我将增加一个变量。

回答

0

请注意,虽然API允许您检查通知,但没有固有的方法可以自动获取它们。您将不得不找出一种定期获取新通知的方式,并将其显示在您的应用中。这超出了这个问题的范围,并被排除在外。

try { 
    Bundle bun = new Bundle(); 
    bun.putString(Facebook.TOKEN, Utility.mFacebook.getAccessToken()); 
    bun.putString("include_read", "true"); // CHANGE "true" to "false" if you need just the unread/unseen notifications 
    String result = Utility.mFacebook.request("/me/notifications", bun); 
    JSONObject JORoot = new JSONObject(result); 
    JSONArray JAFeeds = JORoot.getJSONArray("data"); 

    Log.e("TEST LENGTH", String.valueOf(JAFeeds.length())); 

} catch (Exception e) { 
    // TODO: handle exception 
} 

现在解析在for loop使用JAFeeds JSONArray内容。如果你只需要计数,您可以使用JAFeeds.length()(见上面的代码中Log.e

注意得到它:既然你在OP的facebook-graph-api标签,我建议使用Graph API的例子。但是,如果您需要使用FQL的解决方案,请告诉我。

更新:

按照由OP注释,加入使用FQL

try { 
    String query = "SELECT notification_id, recipient_id, object_id, object_type, sender_id, title_text, body_text, href, created_time FROM notification WHERE recipient_id=me() AND is_unread = 1 AND is_hidden = 0" 
    Bundle newNotifications = new Bundle(); 
    newNotifications.putString("method", "fql.query"); 
    newNotifications.putString("query", queryStatus); 
    String responseNewNotifications = Utility.mFacebook.request(newNotifications); 
    JSONArray JANotifications = new JSONArray(responseNewNotifications); 

    Log.e("TEST LENGTH", String.valueOf(JANotifications.length())); 

} catch (Exception e) { 
    // TODO: handle exception 
} 

无论是图形API溶液以及所述FQL溶液替代是生产代码和工作,因为它们应该。如果有某些具体的内容不起作用,请评论或更新问题的OP。

+0

是的......你可以提供给我FQL解决方案....这个不工作...... thx – 2013-03-13 21:31:37

+0

@ dany's:让我到办公室去查看FQL代码。但是什么都行不通?这是生产中使用的代码,并且工作完美。 – 2013-03-14 03:09:36

+0

也许我不知道初始化Facebook会话...你可以请提供一些完整的?...我的意思是我认为我需要权限,我需要设置一个ACCES TOCKEN和一个APP ID,什么是为了做所有这些...非常感谢,如果你能说出 – 2013-03-14 11:02:07