{"id":1654,"date":"2022-08-30T15:18:20","date_gmt":"2022-08-30T15:18:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/send-app-request-to-facebook-friends-in-android-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:20","modified_gmt":"2022-08-30T15:18:20","slug":"send-app-request-to-facebook-friends-in-android-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/send-app-request-to-facebook-friends-in-android-collection-of-common-programming-errors\/","title":{"rendered":"Send app request to facebook friends in Android-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to send app request to fb friends but failed to do.I have tried the Hackbook sample code.but i am not getting any request.<\/p>\n<p>Here is the code:<\/p>\n<pre><code> Bundle params = new Bundle();\n          params.putString(\"message\", \"Learn how to make your Android apps social\");         \n          Utility.mFacebook.dialog(Hackbook.this, \"apprequests\", params,new AppRequestsListener());\n\npublic class AppRequestsListener extends BaseDialogListener {\n        @Override\n        public void onComplete(Bundle values) {\n            Toast toast = Toast.makeText(getApplicationContext(), \"App request sent\",Toast.LENGTH_SHORT);\n            toast.show();\n        }\n\n        @Override\n        public void onFacebookError(FacebookError error) {\n            Toast.makeText(getApplicationContext(), \"Facebook Error: \" + error.getMessage(),\n                    Toast.LENGTH_SHORT).show();\n        }\n\n        @Override\n        public void onCancel() {\n            Toast toast = Toast.makeText(getApplicationContext(), \"App request cancelled\",\n                    Toast.LENGTH_SHORT);\n            toast.show();\n        }\n    }\n<\/code><\/pre>\n<p>Using the Above code toast message is showing but i am not getting any request.<\/p>\n<p>I have tried another code too..<\/p>\n<p>here is the code:<\/p>\n<pre><code>private void sendRequestDialog() {\n        Bundle params = new Bundle();\n        params.putString(\"message\",\n                \"Learn how to make your Android apps social\");\n\n        WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(\n                Hackbook.this, Session.getActiveSession(), params))\n                .setOnCompleteListener(new OnCompleteListener() {\n                    @Override\n                    public void onComplete(Bundle values,\n                            FacebookException error) {\n                        if (error != null) {\n                            if (error instanceof FacebookOperationCanceledException) {\n                                Toast.makeText(\n                                        Hackbook.this.getApplicationContext(),\n                                        \"Request cancelled\", Toast.LENGTH_SHORT)\n                                        .show();\n                            } else {\n                                Toast.makeText(\n                                        Hackbook.this.getApplicationContext(),\n                                        \"Network Error\", Toast.LENGTH_SHORT)\n                                        .show();\n                            }\n                        } else {\n                            final String requestId = values\n                                    .getString(\"request\");\n                            if (requestId != null) {\n                                Toast.makeText(\n                                        Hackbook.this.getApplicationContext(),\n                                        \"Request sent\", Toast.LENGTH_SHORT)\n                                        .show();\n                            } else {\n                                Toast.makeText(\n                                        Hackbook.this.getApplicationContext(),\n                                        \"Request cancelled\", Toast.LENGTH_SHORT)\n                                        .show();\n                            }\n                        }\n                    }\n                }).build();\n        requestsDialog.show();\n    }\n<\/code><\/pre>\n<p>Using this above code i am getting error:<\/p>\n<pre><code>09-18 14:42:50.102: E\/InputEventReceiver(1310): Exception dispatching input event.\n09-18 14:42:50.102: E\/MessageQueue-JNI(1310): Exception in MessageQueue callback: handleReceiveCallback\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310): java.lang.NullPointerException: Argument 'session' cannot be null\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.facebook.internal.Validate.notNull(Validate.java:29)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.facebook.widget.WebDialog$BuilderBase.(WebDialog.java:392)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.facebook.widget.WebDialog$RequestsDialogBuilder.(WebDialog.java:684)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.facebook.android.Hackbook.sendRequestDialog(Hackbook.java:520)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.facebook.android.Hackbook.onItemClick(Hackbook.java:230)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.widget.AdapterView.performItemClick(AdapterView.java:298)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.widget.AbsListView.performItemClick(AbsListView.java:1268)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.widget.AbsListView$PerformClick.run(AbsListView.java:3055)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.widget.AbsListView.onTouchEvent(AbsListView.java:3961)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.View.dispatchTouchEvent(View.java:7241)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2179)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1914)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1928)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2113)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1466)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.app.Activity.dispatchTouchEvent(Activity.java:2436)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2061)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.View.dispatchPointerEvent(View.java:7425)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3376)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3308)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4402)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4380)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4484)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.os.MessageQueue.nativePollOnce(Native Method)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.os.MessageQueue.next(MessageQueue.java:125)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.os.Looper.loop(Looper.java:124)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at android.app.ActivityThread.main(ActivityThread.java:4918)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at java.lang.reflect.Method.invokeNative(Native Method)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at java.lang.reflect.Method.invoke(Method.java:511)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)\n09-18 14:42:50.142: E\/MessageQueue-JNI(1310):   at dalvik.system.NativeStart.main(Native Method)\n09-18 14:42:50.152: D\/AndroidRuntime(1310): Shutting down VM\n09-18 14:42:50.152: W\/dalvikvm(1310): threadid=1: thread exiting with uncaught exception (group=0x40ef7438)\n<\/code><\/pre>\n<p>Could somebody help me out.@Thanks<\/p>\n<ol>\n<li>\n<pre><code>WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(Hackbook.this, Session.getActiveSession(), params))\n<\/code><\/pre>\n<p>The error is that the session Variable is null..Please make sure you did initialised it correctly in the prior codes..<\/p>\n<\/li>\n<li>\n<p>I don&#8217;t see any code that initialize Session variable.<\/p>\n<p>The official facebook page from where you got your code says the following<\/p>\n<p>&#8221; Prerequisites<\/p>\n<p>Before you begin, make sure you&#8217;ve already set up Facebook Login. This ensures you have the prerequisites and your app is ready for additional Facebook integration. &#8220;<\/p>\n<p>My guess is that user doesn&#8217;t have an active session. If it doesn&#8217;t ask you to log in to facebook or you are not already logged in then you won&#8217;t have a valid session which means the &#8220;Session.getActiveSession()&#8221; will return null.<\/p>\n<\/li>\n<li>\n<p>First see this link:<\/p>\n<p><strong>Facebook Session<\/strong><\/p>\n<p>also see this <strong>Android SDK for Facebook App Tutorial<\/strong><\/p>\n<p>and have you tried this:<\/p>\n<pre><code>    \n        \n            \n                \n                \n            \n        \n        \n        \n    \n<\/code><\/pre>\n<p>where <code>@string\/app_id<\/code> attribute of <code>meta<\/code> tag is defined in your <code>string.xml<\/code><\/p>\n<h2>edited:<\/h2>\n<p><strong>Try to search <code>sessionId<\/code> where is storing and where is used.<\/strong><\/p>\n<p><strong>Maybe you have problem to storing <code>sessionId<\/code> and getting error while fetching current <code>sessionId<\/code><\/strong><\/p>\n<p><strong>Happy Coding \ud83d\ude42<\/strong><\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:25:07. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am trying to send app request to fb friends but failed to do.I have tried the Hackbook sample code.but i am not getting any request. Here is the code: Bundle params = new Bundle(); params.putString(&#8220;message&#8221;, &#8220;Learn how to make your Android apps social&#8221;); Utility.mFacebook.dialog(Hackbook.this, &#8220;apprequests&#8221;, params,new AppRequestsListener()); public class AppRequestsListener extends BaseDialogListener { @Override [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1654","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1654"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1654\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}