i trying access friends' birthdays using latest facebook sdk. due latest updates, forced call api multiple times accomplish this. once fetch friends , use user-id
query birthdays.
the second query, inner query birthdays, being skipped altogether.
and not sure if doing right.
here background asynctask
class contains calls :
/** * background async task load friends making calls graph api * */ class loadallfriends extends asynctask<string, string, string> { /** * before starting background thread show progress dialog * */ @override protected void onpreexecute() { super.onpreexecute(); ... } /** * getting friends , birthdays api * */ protected string doinbackground(string... args) { try { final accesstoken accesstoken = accesstoken.getcurrentaccesstoken(); graphrequestasynctask graphrequestasynctask = new graphrequest( accesstoken, "/me/friends", null, httpmethod.get, new graphrequest.callback() { public void oncompleted(graphresponse response) { try { friends = response.getjsonobject().getjsonarray("data"); log.d("friends length",string.valueof(friends.length())); (int l=0; l < friends.length(); l++) { final hashmap hm = new hashmap<string, date>(); hm.put("uid", friends.getjsonobject(l).getstring("id")); hm.put("name",friends.getjsonobject(l).getstring("name")); graphrequestasynctask graphrequestasynctask = new graphrequest( accesstoken, "/"+hm.get("uid"), null, httpmethod.get, new graphrequest.callback() { public void oncompleted(graphresponse response) { try { jsonarray birthday = response.getjsonobject().getjsonarray("data"); log.d("birthday",(string) birthday.getjsonobject(0).get("birthday")); hm.put("date", (date) birthday.getjsonobject(0).get("birthday")); } catch (exception e) { e.printstacktrace(); } }}).executeasync(); friendslist.add(hm); } dateformat dateformat = new simpledateformat("mm/dd/yy"); calendar cal = calendar.getinstance(); date date1 = dateformat.parse(dateformat.format(cal.gettime())); cal.add(calendar.date, 30); date date2 = dateformat.parse(dateformat.format(cal.gettime())); iterator<hashmap<string, object>> iter = friendslist.iterator(); while (iter.hasnext()) { hashmap<string, object> map = iter.next(); log.d("uid", (string) map.get("uid")); log.d("name", (string) map.get("name")); log.d("date", (string) map.get("date")); /*if (date1.compareto((date) map.get("date")) < 0 || date2.compareto((date) map.get("date")) > 0) { friendslist.remove(map); }*/ } } catch (jsonexception e) { e.printstacktrace(); } catch (parseexception e) { e.printstacktrace(); } } } ).executeasync(); if (friendslist.size() > 0) { friendsfound = true; } else { friendsfound = false; } } catch(nullpointerexception e){ e.printstacktrace(); } catch(runtimeexception e){ e.printstacktrace(); } return null; } /** * after completing background task dismiss progress dialog * **/ protected void onpostexecute(string file_url) { // dismiss dialog after getting events pdialog.dismiss(); // updating ui background thread runonuithread(new runnable() { public void run() { ... } }); } }
here :
log.d("birthday",(string) birthday.getjsonobject(0).get("birthday"));
in inner api call not displayed in terminal. log output being displayed friends.length()
, iterator , uid
, name
. log date
throws following error :
androidruntime: fatal exception: main process: com.supre.www.surprise, pid: 18142 java.lang.nullpointerexception: println needs message @ android.util.log.println_native_inner(native method) @ android.util.log.println_native(log.java:290) @ android.util.log.d(log.java:323) @ com.supre.www.surprise.homeactivity$loadallfriends$1.oncompleted(homeactivity.java:237) @ com.facebook.graphrequest$5.run(graphrequest.java:1368) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5312) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:901) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:696)
please help!
you can´t birthdays of friends did not authorize app, privacy reasons. friend permissions have been removed v2.0 of graph api: https://developers.facebook.com/docs/apps/changelog#v2_0
you can birthdays of friends authorized app user_friends
, user_birthday
, following api call: me/friends?fields=name,birthday
Comments
Post a Comment