Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Undeprecate Facebook Code

Could someone please help me undeprecate this bit of code? This is the example give from Facebook (on how to connect to a FB account - https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/ ), however the marked line:

          Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { 

is deprecated. I tried to replace it with:

    Request.newMeRequest( session, callback, executeAsync() );   

However, the code is nested so confusingly that it messes it all up. I would appreciate any help you could give as I've been at this all day.

// start Facebook Login Session.openActiveSession(this, true, new Session.StatusCallback() {    // callback when session changes state   @Override   public void call(Session session, SessionState state, Exception exception) {     if (session.isOpened()) {        // make request to the /me API       Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { // *DEPRECATED          // callback after Graph API response with user object         @Override         public void onCompleted(GraphUser user, Response response) {           if (user != null) {             TextView welcome = (TextView) findViewById(R.id.welcome);             welcome.setText("Hello " + user.getName() + "!");           }         }       });     }   } }); 

}

Regards

like image 328
gjnave Avatar asked Sep 17 '13 03:09

gjnave


People also ask

Why am I not getting my SMS code from Facebook?

If you're not receiving your text message (SMS) verification codes, you may have turned off text messages from Facebook. Learn how to turn text messages (SMS) back on.


1 Answers

Replace your Request.executeMeRequestAsync with:

Request.newMeRequest(session, new Request.GraphUserCallback() {    // callback after Graph API response with user object   @Override   public void onCompleted(GraphUser user, Response response) {     if (user != null) {       TextView welcome = (TextView) findViewById(R.id.welcome);       welcome.setText("Hello " + user.getName() + "!");     }   } }).executeAsync(); 

i.e. Nothing changes except you're calling a slightly different method and putting .executeAsync() at the end.

like image 85
Ming Li Avatar answered Sep 19 '22 13:09

Ming Li