Importing facebook birthday list to my android app -
i want import facebook birthdays of friends app. app capable of creating new birthday events. long procedure add each , every birthday, instead want code import facebook friends birthdays app. have used facebook session nothing till now
facebook = new facebook(constants.fb_app_id); session session = new session(getapplicationcontext()); if (session.isopened()) { toast.maketext(getapplicationcontext(), session.getstate().tostring(), toast.length_long).show(); } else toast.maketext(getapplicationcontext(), session.getstate().tostring(), toast.length_long).show(); fbrunner = new asyncfacebookrunner(facebook);
also have created request
private void importbirthdayfromfb() { toast.maketext(getapplicationcontext(), "clicked on fb button", toast.length_long).show(); fbrunner.request("maxparera/friends", new requestlistener() { @suppresswarnings("unchecked") @override public void oncomplete(string response, object state) { string keys = ""; try { jsonobject profile = new jsonobject(response); // getting name of user iterator<string> keysiterator = profile.keys(); if (keysiterator != null) { while (keysiterator.hasnext()) { keys += keysiterator.next().tostring(); } toast.maketext(getapplicationcontext(), keys, toast.length_long).show(); } final string name = profile.getstring("name"); // getting name of user toast.maketext(getapplicationcontext(), name: " + name, toast.length_long).show(); } catch (final jsonexception e) { e.printstacktrace(); } catch (final exception e) { e.printstacktrace(); } } });
but not getting name, instead getting exception, sating oauthexception please suggest me asap
maybe session dont have permission friend's birthday.
can request permission below:
loginbutton authbutton = (loginbutton) view.findviewbyid(r.id.authbutton); authbutton.setfragment(this); authbutton.setreadpermissions(arrays.aslist("user_friends, read_friendlists));
layout file:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.facebook.widget.loginbutton android:id="@+id/authbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margintop="30dp" /> </linearlayout>
note: uses facebook sdk 3.8, can refer sample more detail.
loginbutton component of facebook sdk.
for full of code:
public class mainfragment extends fragment { private static final string tag = "mainfragment"; private uilifecyclehelper uihelper; private session.statuscallback callback = new session.statuscallback() { @override public void call(session session, sessionstate state, exception exception) { onsessionstatechange(session, state, exception); log.i(tag, "session: " +session.tostring()); log.i(tag, "state: " +state.tostring()); if(exception!=null) log.i(tag, "exception: " +exception.tostring()); } }; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); uihelper = new uilifecyclehelper(getactivity(), callback); uihelper.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.activity_main, container, false); loginbutton authbutton = (loginbutton) view.findviewbyid(r.id.authbutton); authbutton.setfragment(this); //request permission authbutton.setreadpermissions(arrays.aslist("user_friends, read_friendlists)); return view; } private void onsessionstatechange(session session, sessionstate state, exception exception) { if (state.isopened()) { try{ log.i(tag, "logged in..."); log.i(tag, "execute request"); request r = new request(session,"/me/friendlists",null,httpmethod.get,new request.callback() { public void oncompleted(response response) { log.i(tag, "oncompleted"); try { //i had friend list log.i(tag, "friend: " + response.getgraphobject().tostring()); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } } } ); r.executeasync(); log.i(tag, "finish request"); }catch (exception ex){ log.e(tag, ex.getmessage()); } } else if (state.isclosed()) { try{ } catch(exception ex){ ex.printstacktrace(); } log.i(tag, "logged out..."); } } @override public void onresume() { super.onresume(); // scenarios main activity launched , user // session not null, session state change notification // may not triggered. trigger if it's open/closed. session session = session.getactivesession(); if (session != null && (session.isopened() || session.isclosed()) ) { onsessionstatechange(session, session.getstate(), null); } uihelper.onresume(); } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); uihelper.onactivityresult(requestcode, resultcode, data); } @override public void onpause() { super.onpause(); uihelper.onpause(); } @override public void ondestroy() { super.ondestroy(); uihelper.ondestroy(); } @override public void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); uihelper.onsaveinstancestate(outstate); } }
Comments
Post a Comment