How to retrieve my location and phone number from facebook in Android? -
i newbie in android.i have integrated facebook android. have retrieved id,name , profile picture. want retrieve phone number , location fb. can't understand permissions settings , all. have done following coding. want explain me step step do. codes follows:
mainactivity.class
session.openforread(new session.openrequest(mainactivity.this).setcallback(statuscallback).setpermissions(permissions)); new request( session, "/me?fields=location", null, httpmethod.get, new request.callback() { public void oncompleted(response response) { // handle result // f map<string, object> responsemap = new hashmap<string, object>(); graphobject graphobject = response.getgraphobject(); responsemap = graphobject.asmap(); string location = responsemap.get("location").tostring(); log.i("location",""+location); } } ).executeasync(); session session = session.getactivesession(); if (session.isopened()) { request.executemerequestasync(session,new request.graphusercallback() { @override public void oncompleted(graphuser user, response response) { // todo auto-generated method stub if(user!=null){ final string t1=user.getid(); final string t2=user.getname(); } } });
error logs:
04-15 10:19:13.024: e/androidruntime(17207): fatal exception: main 04-15 10:19:13.024: e/androidruntime(17207): java.lang.runtimeexception: unable start activity componentinfo{com.example.taskmanager/com.example.taskmanager.mainactivity}: java.lang.unsupportedoperationexception: session: attempt made open opened session. 04-15 10:19:13.024: e/androidruntime(17207): @ android.app.activitythread.performlaunchactivity(activitythread.java:2114) 04-15 10:19:13.024: e/androidruntime(17207): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2139) 04-15 10:19:13.024: e/androidruntime(17207): @ android.app.activitythread.access$700(activitythread.java:143) 04-15 10:19:13.024: e/androidruntime(17207): @ android.app.activitythread$h.handlemessage(activitythread.java:1241) 04-15 10:19:13.024: e/androidruntime(17207): @ android.os.handler.dispatchmessage(handler.java:99) 04-15 10:19:13.024: e/androidruntime(17207): @ android.os.looper.loop(looper.java:137) 04-15 10:19:13.024: e/androidruntime(17207): @ android.app.activitythread.main(activitythread.java:4960) 04-15 10:19:13.024: e/androidruntime(17207): @ java.lang.reflect.method.invokenative(native method) 04-15 10:19:13.024: e/androidruntime(17207): @ java.lang.reflect.method.invoke(method.java:511) 04-15 10:19:13.024: e/androidruntime(17207): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038) 04-15 10:19:13.024: e/androidruntime(17207): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:805) 04-15 10:19:13.024: e/androidruntime(17207): @ dalvik.system.nativestart.main(native method) 04-15 10:19:13.024: e/androidruntime(17207): caused by: java.lang.unsupportedoperationexception: session: attempt made open opened session. 04-15 10:19:13.024: e/androidruntime(17207): @ com.facebook.session.open(unknown source) 04-15 10:19:13.024: e/androidruntime(17207): @ com.facebook.session.openforread(unknown source) 04-15 10:19:13.024: e/androidruntime(17207): @ com.example.taskmanager.mainactivity.updateview(mainactivity.java:85) 04-15 10:19:13.024: e/androidruntime(17207): @ com.example.taskmanager.mainactivity.oncreate(mainactivity.java:59) 04-15 10:19:13.024: e/androidruntime(17207): @ android.app.activity.performcreate(activity.java:5203) 04-15 10:19:13.024: e/androidruntime(17207): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1094) 04-15 10:19:13.024: e/androidruntime(17207): @ android.app.activitythread.performlaunchactivity(activitythread.java:2078) 04-15 10:19:13.024: e/androidruntime(17207): ... 11 more
you cannot fetch phone number of user.
to fetch location, need the:
- api call:
/me?fields=location
- demo - permission:
user_location
check here how ask additional permissions using android sdk.
code location:
new request( session, "/me?fields=location", null, httpmethod.get, new request.callback() { public void oncompleted(response response) { /* handle result */ } } ).executeasync();
see fields available user: /{user-id}
Comments
Post a Comment