2

这是来自以下页面的代码: https ://developers.facebook.com/docs/android/share-dialog/#setup

我试图让它工作,但在实例化 UILifecycleHelper 类时对“回调”参数感到非常困惑。(查看教程代码)我看不出这个变量是从哪里来的。我试图创建一个空对象并传递它,但(惊喜)得到了 NullPointerException。

Facebook 是否在这里忘记了一步,或者是否有一些隐含的知识让我缺乏理解回调又回来困扰我?

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

uiHelper = new UiLifecycleHelper(this, callback);    // line 45 in code
uiHelper.onCreate(savedInstanceState);
}

谢谢您的帮助

// 编辑(再次) - 错误的跟踪

这是堆栈跟踪 - 还有很多 ECLIPSE 错误需要处理(不知道如何摆脱它们),所以忽略这些:

09-16 19:24:20.533: E/AndroidRuntime(1348): FATAL EXCEPTION: main
09-16 19:24:20.533: E/AndroidRuntime(1348): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.theperspectableone.carddisplayertemplate/com.theperspectableone.carddisplayertemplate.MainActivity}: java.lang.NullPointerException: Argument 'applicationId' cannot be null
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.os.Looper.loop(Looper.java:137)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.app.ActivityThread.main(ActivityThread.java:5103)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at java.lang.reflect.Method.invokeNative(Native Method)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at java.lang.reflect.Method.invoke(Method.java:525)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at dalvik.system.NativeStart.main(Native Method)
09-16 19:24:20.533: E/AndroidRuntime(1348): Caused by: java.lang.NullPointerException: Argument 'applicationId' cannot be null
09-16 19:24:20.533: E/AndroidRuntime(1348):     at com.facebook.internal.Validate.notNull(Validate.java:29)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at com.facebook.Session.<init>(Session.java:227)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at com.facebook.Session.<init>(Session.java:212)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at com.facebook.UiLifecycleHelper.onCreate(UiLifecycleHelper.java:87)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at com.theperspectableone.carddisplayertemplate.MainActivity.onCreate(MainActivity.java:45)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.app.Activity.performCreate(Activity.java:5133)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-16 19:24:20.533: E/AndroidRuntime(1348):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-16 19:24:20.533: E/AndroidRuntime(1348):     ... 11 more
4

1 回答 1

1

答案是 Idipaolo 所说的……您必须遵循设置说明以及共享对话框。

您最终需要使用 Facebook 创建一个开发者帐户,这还需要以下内容:

Having "keytool" in your computer ENVIRONMENT VARIABLES
Installing and having "openssl" in your computer ENVIRONMENT VARIABLES
Creating a keystore
Creating a Key
Creating a new App on the Facebook Developer page
Putting the Key in the app info page
Getting an App ID from Facebook
A plethora of other setup things in your Android file

这个网站帮助我获得了密钥(尽管实际的 FB 代码已被弃用):http ://www.androidhive.info/2012/03/android-facebook-connect-tutorial/

这使对话框启动并运行(尽管有一行已被弃用,但仍然让我感到悲伤*):https ://developers.facebook.com/docs/android/share-dialog/#setup

*Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
于 2013-09-17T03:51:44.533 回答