I'm having android Button for Login.
below is the onclick listener of that button.
btnLoginFB.setOnClickListener(new View.OnClickListener() {
@
Override
public void onClick(View v) {
Session s = new Session(Startup.this);
Session.setActiveSession(s);
Session.OpenRequest request = new Session.OpenRequest(Startup.this);
List < String > permissions = new ArrayList < String > ();
permissions.add("friends_birthday");
permissions.add("friends_location");
request.setPermissions(permissions);
request.setCallback(new Session.StatusCallback() {
@
Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() {
@
Override
public void onCompleted(List < GraphUser > users, Response response) {
if (users != null) {
for (int i = 0; i < users.size(); i++) {
String frndLoc = "empty";
try {
users.get(i).getLocation().getProperty("name");
frndLoc = "" + users.get(i).getLocation().getProperty("name");
} catch (Exception e) {}
Toast.makeText(Startup.this, users.get(i).getBirthday() + " - " +
users.get(i).getName() + "\n" +
frndLoc, Toast.LENGTH_LONG).show();
}
}
}
}).executeAsync();
} // end of if (session.isOpened())
} // end of call
});
s.openForRead(request);
}
});
The problem is I'm getting null for both B'day and Location of friend.
Request friendRequest = Request.newMyFriendsRequest(activeSession, new GraphUserListCallback() {
@Override
public void onCompleted(final List<GraphUser> users, Response response) {
ArrayList<String> o = new ArrayList<String>();
for (GraphUser u : users) {
o.add(u.getInnerJSONObject().toString());
}
getSherlockActivity().startService(
new Intent(getSherlockActivity(), InsertInDBService.class).putExtra("fbdata", o));
}
}
});
Parse the reponse
int count = users.size();
for (int i = 0; i < count; i++) {
String name = "", id = "", photoUrl = "";
String birthday = "", location = "";
String website = "";
JSONObject o = null;
try {
o = new JSONObject(users.get(i));
} catch (JSONException e) {
}
try {
id = o.getString("id");
name = o.getString("name");
photoUrl = o.getJSONObject("picture").getJSONObject("data").getString("url");
} catch (JSONException e) {
e.printStackTrace();
dbFacebookMain.deleteFACEBOOK();
}
try {
location = o.getJSONObject("location").getString("name");
} catch (JSONException e) {
}
try {
birthday = o.getString("birthday");
} catch (JSONException e) {
}
try {
website = o.getString("website");
} catch (JSONException e) {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.