Reputation: 72
I want to display my Facebook name with this simple app that login after a button click that calls login()
.
The session is opened correctly, but the Request.GraphUserCallback does not work it seems that return null.
LogCat doesn't display any error when i launch my app, but i can't see my user.name()
on the Toast that i showed on the onCompleted when the Graph API returns the user.
Here's my code without the imports and without the layout:
public class MainActivity extends Activity {
private Session.StatusCallback statusCallback;
private Request.GraphUserCallback requestGraphUserCallback;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(), "Ci siamo", Toast.LENGTH_SHORT).show();
statusCallback= new SessionStatusCallback();
requestGraphUserCallback = new RequestGraphUserCallback();
}
public void login(View view){
Toast.makeText(getApplicationContext(), "Login", Toast.LENGTH_SHORT).show();
// start Facebook Login
Session.openActiveSession(this, true, statusCallback);
Toast.makeText(getApplicationContext(), "finito login", Toast.LENGTH_SHORT).show();
}
//CLASSE SESSIONE
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.newMeRequest(session, requestGraphUserCallback);
}
}
}
//CLASSE GRAPH
private class RequestGraphUserCallback implements Request.GraphUserCallback{
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Toast.makeText(getApplicationContext(), user.getName(), Toast.LENGTH_SHORT).show();
}
}
}
}
What i'm doing wrong? Facebook documentation is very uncomprehensive. Already read this question and this tutorial (that use the contract version of my code).
Upvotes: 1
Views: 3813
Reputation: 2540
You are not executing the request. In your SessionStatusCallback, after creating the request, you should call the executeAsync()
method on it.
Upvotes: 6