1

我正在尝试向 fb 朋友发送应用请求,但没有成功。我尝试了 Hackbook 示例代码。但我没有收到任何请求。

这是代码:

 Bundle params = new Bundle();
          params.putString("message", "Learn how to make your Android apps social");         
          Utility.mFacebook.dialog(Hackbook.this, "apprequests", params,new AppRequestsListener());

public class AppRequestsListener extends BaseDialogListener {
        @Override
        public void onComplete(Bundle values) {
            Toast toast = Toast.makeText(getApplicationContext(), "App request sent",Toast.LENGTH_SHORT);
            toast.show();
        }

        @Override
        public void onFacebookError(FacebookError error) {
            Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(),
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel() {
            Toast toast = Toast.makeText(getApplicationContext(), "App request cancelled",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    }

使用上面的代码 toast 消息正在显示,但我没有收到任何请求。

我也尝试了另一个代码..

这是代码:

private void sendRequestDialog() {
        Bundle params = new Bundle();
        params.putString("message",
                "Learn how to make your Android apps social");

        WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(
                Hackbook.this, Session.getActiveSession(), params))
                .setOnCompleteListener(new OnCompleteListener() {
                    @Override
                    public void onComplete(Bundle values,
                            FacebookException error) {
                        if (error != null) {
                            if (error instanceof FacebookOperationCanceledException) {
                                Toast.makeText(
                                        Hackbook.this.getApplicationContext(),
                                        "Request cancelled", Toast.LENGTH_SHORT)
                                        .show();
                            } else {
                                Toast.makeText(
                                        Hackbook.this.getApplicationContext(),
                                        "Network Error", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        } else {
                            final String requestId = values
                                    .getString("request");
                            if (requestId != null) {
                                Toast.makeText(
                                        Hackbook.this.getApplicationContext(),
                                        "Request sent", Toast.LENGTH_SHORT)
                                        .show();
                            } else {
                                Toast.makeText(
                                        Hackbook.this.getApplicationContext(),
                                        "Request cancelled", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        }
                    }
                }).build();
        requestsDialog.show();
    }

使用上面的代码我收到错误:

09-18 14:42:50.102: E/InputEventReceiver(1310): Exception dispatching input event.
09-18 14:42:50.102: E/MessageQueue-JNI(1310): Exception in MessageQueue callback: handleReceiveCallback
09-18 14:42:50.142: E/MessageQueue-JNI(1310): java.lang.NullPointerException: Argument 'session' cannot be null
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.internal.Validate.notNull(Validate.java:29)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.widget.WebDialog$BuilderBase.<init>(WebDialog.java:392)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.widget.WebDialog$RequestsDialogBuilder.<init>(WebDialog.java:684)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.android.Hackbook.sendRequestDialog(Hackbook.java:520)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.facebook.android.Hackbook.onItemClick(Hackbook.java:230)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.widget.AdapterView.performItemClick(AdapterView.java:298)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.widget.AbsListView.performItemClick(AbsListView.java:1268)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.widget.AbsListView$PerformClick.run(AbsListView.java:3055)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.widget.AbsListView.onTouchEvent(AbsListView.java:3961)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.View.dispatchTouchEvent(View.java:7241)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2179)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1914)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2113)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1466)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.app.Activity.dispatchTouchEvent(Activity.java:2436)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2061)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.View.dispatchPointerEvent(View.java:7425)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3376)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3308)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4402)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4380)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4484)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.os.MessageQueue.nativePollOnce(Native Method)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.os.MessageQueue.next(MessageQueue.java:125)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.os.Looper.loop(Looper.java:124)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at android.app.ActivityThread.main(ActivityThread.java:4918)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at java.lang.reflect.Method.invokeNative(Native Method)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at java.lang.reflect.Method.invoke(Method.java:511)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
09-18 14:42:50.142: E/MessageQueue-JNI(1310):   at dalvik.system.NativeStart.main(Native Method)
09-18 14:42:50.152: D/AndroidRuntime(1310): Shutting down VM
09-18 14:42:50.152: W/dalvikvm(1310): threadid=1: thread exiting with uncaught exception (group=0x40ef7438)

有人可以帮我吗。@谢谢

4

3 回答 3

0

首先看这个链接:

脸书专场

另请参阅此Android SDK for Facebook App 教程

你试过这个吗:

    <application android:label="@string/app_name"
                 android:icon="@drawable/icon"
                 android:theme="@android:style/Theme.NoTitleBar"
            >
        <activity android:name=".HelloFacebookSampleActivity"
                  android:label="@string/app_name"
                  android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="com.facebook.LoginActivity"
                  android:theme="@android:style/Theme.Translucent.NoTitleBar"
                  android:label="@string/app_name" />
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
    </application>

标签的属性在您@string/app_idmetastring.xml

编辑:

尝试搜索sessionId存储位置和使用位置。

也许您sessionId在获取电流时存储和获取错误有问题sessionId

快乐编码:)

于 2013-09-25T11:25:34.997 回答
0

我没有看到任何初始化 Session 变量的代码。

您获取代码的官方 facebook 页面显示以下内容

" 先决条件

开始之前,请确保您已设置 Facebook 登录。这可确保您具备先决条件,并且您的应用已准备好进行其他 Facebook 集成。"

我的猜测是用户没有活动会话。如果它没有要求您登录 facebook 或者您尚未登录,那么您将没有有效的会话,这意味着“Session.getActiveSession()”将返回 null。

于 2013-09-25T05:10:59.970 回答
0
WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(Hackbook.this, Session.getActiveSession(), params))

错误是会话变量为空..请确保您在之前的代码中正确初始化了它..

于 2013-09-23T19:19:11.277 回答