[英]FQL Query to get Facebook Friends Birthdays in next 30 days using Android
[英]Facebook friends birthdays in Android
在Android中,獲得朋友生日的最簡單方法是什么? 還是關系狀態? 使用FQL或通過Android API SDK for Android請求它?
謝謝。
Bundle params = new Bundle();
params.putString("fields","birthday");
JSONObject jObject1 = new JSONObject(authenticatedFacebook.request("me/friends",params));
現在,如果您打印jobject1,您將獲得所有朋友的生日列表..
響應將采用JSON格式,您必須從中獲取值。
authenticatedFacebook是Facebook的對象..
如需進一步說明,請查看此鏈接 .....
private static final String[] PERMISSIONS =
new String[] {"friends_birthday","read_stream", "offline_access"};
確保您允許訪問朋友的生日日期..
什么是最簡單的方式來獲得朋友的生日? 還是關系狀態?
relationship status of a user's friends in one query like this: 使用FQL,我們可以在一個查詢中獲得用戶朋友的生日關系狀態,如下所示:
SELECT uid, name, birthday_date, relationship_status
FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())
可以使用Facebook Android SDK在Android上實現,如下所示:
String query = "SELECT uid, name, birthday_date, relationship_status FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())"
Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query", query);
mAsyncFacebookRunner.request(null, params, new FQLRequestListener())
其中FQLRequestListener擴展了RequestListener。
JSON響應將如下所示:
{
"data": [
{
"uid": 1234567890,
"name": "John Smith",
"birthday_date": "06/16",
"relationship_status": "Married"
},
{
"uid": etc...
你需要的
friends_birthday
允許
try {
parameters.putString("format", "json");
parameters.putString(TOKEN, mAccessToken);
String url = "https://graph.facebook.com/me/friends?fields=id,name,birthday,location";
String response = Util.openUrl(url, "GET", parameters);
JSONObject obj = Util.parseJson(response);
Log.i("json Response", obj.toString());
JSONArray array = obj.optJSONArray("data");
if (array != null) {
for (int i = 0; i < array.length(); i++) {
String name = array.getJSONObject(i).getString("name");
String id = array.getJSONObject(i).getString("id");
Log.i(name,id);
}
}
}
您需要添加權限
friends_birthday
friends_location
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.