Problems with the Request.executeMeRequestAsync (session, Request.GraphUserCallback ()) function

I am following a tutorial to login to an android app using facebook.

I had a lot of problems with hash keys and everything, and I think I solved them all, because my session already got OPENED state.

The problem I am facing right now is that after logging into facebook, when the session is already open, the code executes Request.executeMeRquestAsync() and it never goes into the onComplete() ... any idea?

Here is the code ...

 package com.example.firstandroidapp; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.Signature; import android.os.Bundle; import android.util.Base64; import android.util.Log; import android.widget.TextView; import com.facebook.Request; import com.facebook.Response; import com.facebook.Session; import com.facebook.SessionState; import com.facebook.model.GraphUser; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 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) { try { PackageInfo info = getPackageManager().getPackageInfo("com.example.firstandroidapp", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.i("Digest: ", Base64.encodeToString(md.digest(), 0)); } } catch (NameNotFoundException e) { Log.e("Test", e.getMessage()); } catch (NoSuchAlgorithmException e) { Log.e("Test", e.getMessage()); } if (session.isOpened()) { // make request to the /me API Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { // callback after Graph API response with user object @Override public void onCompleted(GraphUser user, Response response) { // it never gets here... if (user != null) { TextView welcome = (TextView) findViewById(R.id.welcome); welcome.setText("Hello " + user.getName() + "!"); } } }); } } }); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); } } 

Thanx is very advanced. David.

+4
source share
2 answers

I had the same problem.

In the tutorial, we are informed of a change in AndroidManifest.xml. In the modification, I put the tags below in the wrong places (I did not use Eclipse to modify the manifest file), and this prevented the callback.

 <manifest ...> ... <application ...> ... <activity android:name="com.facebook.LoginActivity"/> ... <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> ... </application> ... <uses-permission android:name="android.permission.INTERNET"/> ... </manifest> 

Try double checking your AndroidManifest.xml. The white paper will be helpful.

+2
source

Session.openActiveSession returns a session directly if it is already open. This may be your problem. In this case, the call cannot be called. (Still in the process of implementing this self.)

Create an instance of SessionCallback before calling it and - if the session is returned directly - call it:

 StatusCallback cb = new StatusCallback() {/* implement */}; Session fbSession = Session.openActiveSession(this, true, cb); if (fbSession != null) { cb.call(fbSession, fbSession.getState(), null); } 

Check the state of the session inside the callback so you don't have to process different states twice.

+1
source

All Articles