我正在尝试向 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)
有人可以帮我吗。@谢谢