Kartik_Agarwal Kartik_Agarwal - 1 month ago 12
Android Question

Facebook Login CallbackManager FacebookCallback called onCancel() every time

I am implementing login via facebook and get user email id using SDK 4.1.0 as shown in facebook documentation but problem occurring is that every time after onActivityResult when registerCallback is called then instead of onSuccess onCancel is called.

package com.dexterous.hellologin;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;


public class MainActivity2 extends ActionBarActivity {

CallbackManager callbackManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();

setContentView(R.layout.activity_main_activity2);

LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("email");
// If using in a fragment
// loginButton.setFragment(this);
// Other app specific specialization
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.e("TAG", "success");
}

@Override
public void onCancel() {
// App code
Log.e("TAG", "onCancel");
}

@Override
public void onError(FacebookException exception) {
// App code
Log.e("TAG", "error");
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
Log.e("TAG", "onActivityResult");
}
}


every time i am getting output

onActivityResult

onCancel

neither i am getting that facebook login screen containing buttons cancel and login.

after uninstall facebook app from mobile error changed to Invalid App ID

and this is stacktrace


06-04 10:55:16.631 19864-19864/com.dexterous.hellologin I/WebViewFactory﹕ Loading com.google.android.webview version 42.0.2311.138 (code 2311138)
06-04 10:55:16.706 19864-19864/com.dexterous.hellologin I/LibraryLoader﹕ Time to load native libraries: 4 ms (timestamps 8772-8776)
06-04 10:55:16.706 19864-19864/com.dexterous.hellologin I/LibraryLoader﹕ Expected native library version number "",actual native library version number ""
06-04 10:55:16.717 19864-19864/com.dexterous.hellologin W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
06-04 10:55:16.816 19864-19864/com.dexterous.hellologin V/WebViewChromiumFactoryProvider﹕ Binding Chromium to main looper Looper (main, tid 1) {28a6fbd9}
06-04 10:55:16.816 19864-19864/com.dexterous.hellologin I/LibraryLoader﹕ Expected native library version number "",actual native library version number ""
06-04 10:55:16.819 19864-19864/com.dexterous.hellologin I/chromium﹕ [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
06-04 10:55:16.834 19864-19864/com.dexterous.hellologin I/BrowserStartupController﹕ Initializing chromium process, singleProcess=true
06-04 10:55:16.838 19864-19864/com.dexterous.hellologin W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
06-04 10:55:16.841 19864-19864/com.dexterous.hellologin E/SysUtils﹕ ApplicationContext is null in ApplicationStatus
06-04 10:55:16.869 19864-19864/com.dexterous.hellologin W/chromium﹕ [WARNING:resource_bundle.cc(286)] locale_file_path.empty()
06-04 10:55:16.870 19864-19864/com.dexterous.hellologin I/chromium﹕ [INFO:aw_browser_main_parts.cc(63)] Load from apk succesful, fd=63 off=46992 len=3337
06-04 10:55:16.871 19864-19864/com.dexterous.hellologin I/chromium﹕ [INFO:aw_browser_main_parts.cc(76)] Loading webviewchromium.pak from, fd:64 off:7953032 len:1161174
06-04 10:55:17.024 19864-19953/com.dexterous.hellologin W/chromium﹕ [WARNING:data_reduction_proxy_config.cc(150)] SPDY proxy OFF at startup
06-04 10:55:17.047 19864-19864/com.dexterous.hellologin W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
06-04 10:55:17.060 19864-19864/com.dexterous.hellologin W/AwContents﹕ onDetachedFromWindow called when already detached. Ignoring
06-04 10:55:24.893 19864-19864/com.dexterous.hellologin W/BindingManager﹕ Cannot call determinedVisibility() - never saw a connection for the pid: 19864
06-04 10:55:26.140 19864-20020/com.dexterous.hellologin E/Adreno-ES20﹕ : Invalid texture format! Returning error!
06-04 10:55:26.140 19864-20020/com.dexterous.hellologin E/Adreno-ES20﹕ : Framebuffer color attachment incomplete. Returning GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT!
06-04 10:55:26.198 19864-19912/com.dexterous.hellologin E/Adreno-ES20﹕ : Invalid texture format! Returning error!
06-04 10:55:26.198 19864-19912/com.dexterous.hellologin E/Adreno-ES20﹕ : Framebuffer color attachment incomplete. Returning GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT!
06-04 10:58:32.287 19864-19864/com.dexterous.hellologin E/TAG﹕ onCancel
06-04 10:58:32.287 19864-19864/com.dexterous.hellologin E/TAG﹕ onActivityResult
06-04 10:59:25.498 19864-19864/com.dexterous.hellologin I/art﹕ Explicit concurrent mark sweep GC freed 16056(1325KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 9MB/16MB, paused 856us total 79.028ms


Manifest



<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<activity
android:name="com.dexterous.hellologin.MainActivity2"
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"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main_activity2" >
</activity>

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="1437829111203883" />

</application>

</manifest>

Answer

Problem is here that you are using Facebook APPId directly and You should use Like this

<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/app_id" />

In sting xml

<string name="app_id">1437829111203883 </string>