I am working on an app that helps in publishing the post on different platforms in a single go. User has to write about their post and add pictures if they want and then select the social media they want to post on like they can select facebook and instagram or facebook,Instagram and X and when the click the button based on the selection post should be publish on there social media account.

What Problem I am facing?

I am able to create a button that helps user to login to facebook and thats working perfectly. But when it comes to publishing a post it doesn't work. Please let me know what I can do to make that code run??

Here is the code snippet for publishing post to facebook.

private void postToFacebook(String token, String msg) {         String url = "https://graph.facebook.com/v17.0/me/feed";         StringRequest stringRequest = new StringRequest(Request.Method.POST, url,                 new Response.Listener<String>() {                     @Override                     public void onResponse(String response) {                         // Handle success                         Log.d("FBResponse", response);                         Toast.makeText(MainActivity.this, "Post Successful!", Toast.LENGTH_SHORT).show();                     }                 }, new Response.ErrorListener() {             @Override             public void onErrorResponse(VolleyError error) {                 // Handle error                 Log.e("FBError", error.toString());                 Toast.makeText(MainActivity.this, "Failed to Post: " + error.getMessage(), Toast.LENGTH_LONG).show();             }         }) {             @Override             protected Map<String, String> getParams() {                 Map<String, String> params = new HashMap<>();                 params.put("message", msg);                 params.put("access_token", token);                 return params;             }         };         RequestQueue queue = Volley.newRequestQueue(this);         queue.add(stringRequest);     } 

This is the error I am getting when I am trying to publish a post.

2024-09-07 07:34:41.2465642-5734  Volley                  com.example.post                     E  [83] NetworkUtility.shouldRetryException: Unexpected response code 403 for https://graph.facebook.com/v17.0/me/feed 2024-09-07 07:34:41.416790-790   StatusBarIconController com.android.systemui                 D  ignoring old pipeline callbacks, because the new mobile icons are enabled 2024-09-07 07:34:41.4845642-5734  Volley                  com.example.post                     E  [83] NetworkUtility.shouldRetryException: Unexpected response code 403 for https://graph.facebook.com/v17.0/me/feed 2024-09-07 07:34:41.4865642-5642  FBError                 com.example.post                     E  com.android.volley.AuthFailureError 

Tag:android, facebook-graph-api

Add a new comment.