Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a login with facebook using Facebook SDK 3.0

Now,i need to click on a button, and that button to activate the login with facebook alert.

Now, until now, i have used the old code, that works,but is deprecated, so i need to use the new one, which i cannot understand. Where does it use the APP_ID string? Now i took the HelloFacebookSample, and the SessionLoginSample, but they both crash when i try to run them on my phone. Then i have tried this code: https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/ But it does the same.

This is what logcat says:

 03-13 14:55:46.497: E/AndroidRuntime(28849): java.lang.RuntimeException: Unable to start activity ComponentInfo{ro.koolnet.android/ro.koolnet.android.ui.activities.LoginActivity}: java.lang.NullPointerException: Argument applicationId cannot be null
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2215)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at android.app.ActivityThread.access$600(ActivityThread.java:145)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at android.os.Handler.dispatchMessage(Handler.java:99)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at android.os.Looper.loop(Looper.java:137)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at android.app.ActivityThread.main(ActivityThread.java:4978)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at java.lang.reflect.Method.invokeNative(Native Method)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at java.lang.reflect.Method.invoke(Method.java:511)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at dalvik.system.NativeStart.main(Native Method)
 03-13 14:55:46.497: E/AndroidRuntime(28849): Caused by: java.lang.NullPointerException: Argument applicationId cannot be null
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at com.facebook.internal.Validate.notNull(Validate.java:29)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at com.facebook.Session.<init>(Session.java:224)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at com.facebook.Session.<init>(Session.java:209)
 03-13 14:55:46.497: E/AndroidRuntime(28849):   at com.facebook.UiLifecycleHelper.onCreate(UiLifecycleHelper.java:73)

Could someone please help me with a working tutorial/example?

Now I have also tried this code: https://github.com/fbsamples/android-3.0-howtos/blob/master/LoginHowTo/src/com/facebook/samples/loginhowto/MainFragment.java

but still i get the same error. Now, i looked throught logcat, and it crashes because the application_id is null (in the sdk code). Now they instantiate it, by using the UIhelper. but when i create the uihelper (UiLifecycleHelper), i do not have an option to pass it the APP_ID, why? should i have the possibility to pass the application_id somewherE?

like image 529
rosu alin Avatar asked Dec 09 '22 17:12

rosu alin


1 Answers

I have to include the application id in the manifest like this:

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

I have this code: https://github.com/fbsamples/android-3.0-howtos/tree/master/LoginHowTo but the only difference is that i need to have an activity, no fragment, so i changed authButton.setFragment(this); with authButton.setSessionStatusCallback(callback); Now the only problem is that, after i log in, with the dialog, it does not enter my onSessionStateChange.

like image 153
rosu alin Avatar answered Dec 11 '22 10:12

rosu alin