Facebook SDK 4.0.1 Login without login button Facebook SDK 4.0.1 Login without login button android android

Facebook SDK 4.0.1 Login without login button


Ok I don't know if you had already solve your problem but here is how I solved it

 List<String> permissionNeeds= Arrays.asList("user_photos", "friends_photos", "email", "user_birthday", "user_friends"); super.onCreate(savedInstanceState);    FacebookSdk.sdkInitialize(getApplicationContext());    mCallbackManager = CallbackManager.Factory.create();    LoginManager.getInstance().logInWithReadPermissions(            this,           permissionNeeds);    LoginManager.getInstance().registerCallback(mCallbackManager,            new FacebookCallback<LoginResult>() {                @Override                public void onSuccess(LoginResult loginResults) {                    GraphRequest request = GraphRequest.newMeRequest(                            loginResults.getAccessToken(),                            new GraphRequest.GraphJSONObjectCallback() {                                @Override                                public void onCompleted(                                        JSONObject object,                                        GraphResponse response) {                                    // Application code                                    Log.v("LoginActivity", response.toString());                                }                            });                    Bundle parameters = new Bundle();                    parameters.putString("fields", "id,name,email,gender, birthday");                    request.setParameters(parameters);                    request.executeAsync();                }                @Override                public void onCancel() {                    Log.e("dd","facebook login canceled");                }                @Override                public void onError(FacebookException e) {                    Log.e("dd", "facebook login failed error");                }            });


Try moving your meta-data and activity under the application node rather than the first activity node.

<application    android:allowBackup="true"    android:icon="@mipmap/ic_launcher"    android:label="@string/app_name"    android:theme="@style/AppTheme" >    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>    <activity        android:name=".MainActivity"        android:label="@string/app_name" >        <intent-filter>            <action android:name="android.intent.action.MAIN" />            <category android:name="android.intent.category.LAUNCHER" />        </intent-filter>    </activity>    <activity android:name="com.facebook.FacebookActivity" /></application>


Your issue is that you use FacebookSdk.sdkInitialize(getApplicationContext()); after setContentView(R.layout.activity_main);. You should use it before setContentView(). A full facebook login example with sample code can be found here.