简体   繁体   English

使用Facebook SDK 3.0登录facebook

[英]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. 现在,我需要点击一个按钮,然后用该按钮通过facebook提醒激活登录。

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? 它在哪里使用APP_ID字符串? Now i took the HelloFacebookSample, and the SessionLoginSample, but they both crash when i try to run them on my phone. 现在我拿了HelloFacebookSample和SessionLoginSample,但是当我尝试在手机上运行它们时它们都崩溃了。 Then i have tried this code: https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/ But it does the same. 然后我尝试了这段代码: https//developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/但它也是如此。

This is what logcat says: 这就是logcat所说的:

 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 现在我也尝试了这段代码: 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). 现在,我查看了logcat,它崩溃了,因为application_id为null(在sdk代码中)。 Now they instantiate it, by using the UIhelper. 现在,他们通过使用UIhelper实例化它。 but when i create the uihelper (UiLifecycleHelper), i do not have an option to pass it the APP_ID, why? 但是当我创建uihelper(UiLifecycleHelper)时,我没有选择将APP_ID传递给它,为什么? should i have the possibility to pass the application_id somewherE? 我是否有可能通过application_id somewherE?

I have to include the application id in the manifest like this: 我必须在清单中包含应用程序ID,如下所示:

<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); 我有这个代码: https//github.com/fbsamples/android-3.0-howtos/tree/master/LoginHowTo但唯一的区别是我需要一个活动,没有片段,所以我改变了authButton.setFragment(this); with authButton.setSessionStatusCallback(callback); with authButton.setSessionStatusCallback(callback); Now the only problem is that, after i log in, with the dialog, it does not enter my onSessionStateChange . 现在唯一的问题是,在我登录后,使用对话框,它不会进入我的onSessionStateChange

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM