Post to FB Wall Using 3.0 SDK

Hi fellow programmers, I’m having difficulty with the new Facebook SDK,

Scenario:

im using snippet so i follow these steps

Why doesn't Android Facebook interface work with snippets?

and now i get incomplete and token id

Now I want to post on my wall, so reality created this function

private void publishStory(Session session) { if (session != null){ // Check for publish permissions session.addCallback(new StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { List<String> PERMISSIONS = Arrays .asList("publish_actions"); session .requestNewPublishPermissions(new Session.NewPermissionsRequest( getActivity(), PERMISSIONS)); Request request = Request.newStatusUpdateRequest( session, "Temple Hello Word Sample", new Request.Callback() { @Override public void onCompleted(Response response) { Log.i("fb:done = ", response.getGraphObject() + "," + response.getError()); } }); request.executeAsync(); } }); 

And put the declaration oncomplete

  public void call(final Session session, SessionState state, Exception exception) { if (session.isOpened()) { Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { publishStory(session); } else { Log.v("FACEBOOK ", "NO ACCESS"); } } }); } 

My problem is this line of code session.addCallback(new StatusCallback() { , it skips the next step, thereby ending the function without posting to my wall.

I am sure that the session is active since I have an application identifier and an access token.

Any help?

thanks

EDIT

I use this code based on the answer below and added new permissions

 private void publishStoryTEST(final Session session) { if (session != null) { Bundle postParams = new Bundle(); postParams.putString("message", "TEST"); Request.Callback callback = new Request.Callback() { public void onCompleted(Response response) { JSONObject graphResponse = response.getGraphObject().getInnerJSONObject(); String postId = null; try { postId = graphResponse.getString("id"); } catch (JSONException e) { Log.i("JSON", "JSON error " + e.getMessage()); } FacebookRequestError error = response.getError(); Log.e("post response", response.toString()); if (error != null) { } else { } } }; List<String> PERMISSIONS = Arrays .asList("publish_actions"); session.requestNewPublishPermissions(new Session.NewPermissionsRequest(getActivity(), PERMISSIONS)); Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback); RequestAsyncTask task = new RequestAsyncTask(request); task.execute(); } } 

But still I get an error message

 The user hasn't authorized the application to perform this action 

Why am I still getting this error? Was permission allowed?

+4
source share
3 answers

The problem is common, I am sharing with you the working source code of the wiring method that I now use in my application.

 private void publishStory(String status) { Session session = Session.getActiveSession(); if (session != null) { Bundle postParams = new Bundle(); postParams.putString("message", status); Request.Callback callback = new Request.Callback() { public void onMalformedURLException(MalformedURLException e) { } public void onIOException(IOException e) { } public void onFileNotFoundException(FileNotFoundExceptione) { } public void onFacebookError(FacebookError e) { } public void onCompleted(Response response) { JSONObject graphResponse = response.getGraphObject().getInnerJSONObject(); String postId = null; try { postId = graphResponse.getString("id"); } catch (JSONException e) { Log.i("JSON", "JSON error " + e.getMessage()); } FacebookRequestError error = response.getError(); Log.e("post response", response.toString()); if (error != null) { } else { } } }; Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback); RequestAsyncTask task = new RequestAsyncTask(request); task.execute(); } } 


Hope this solves your problem.

EDIT:
Please refer to the following links for detailed information on setting up the Facebook SDK 3.0 with the appropriate publishing rights and features.
Android fails to post to facebook after login
http://www.kpbird.com/2013/03/android-login-using-facebook-sdk-30.html

+1
source

// Try under the code

 private void postData() { lnrPbr.setVisibility(View.VISIBLE); isSharingData = true; Session session = Session.getActiveSession(); if (session != null) { Bundle postParams = new Bundle(); postParams.putString("name", getIntent().getStringExtra("IN_SHARE_CAPTION") == null ? "" : getIntent().getStringExtra("IN_SHARE_CAPTION")); postParams.putString("caption", getIntent().getStringExtra("IN_SHARE_CAPTION") == null ? "" : getIntent().getStringExtra("IN_SHARE_CAPTION")); postParams.putString("description", getIntent().getStringExtra("IN_SHARE_DESCRIPTION") == null ? "" : getIntent().getStringExtra("IN_SHARE_DESCRIPTION")); postParams.putString("link", getIntent().getStringExtra("IN_SHARE_SHARELINK") == null ? "" : getIntent().getStringExtra("IN_SHARE_SHARELINK")); postParams.putString("picture", getIntent().getStringExtra("IN_SHARE_THUMB") == null ? "" : getIntent().getStringExtra("IN_SHARE_THUMB")); postParams.putString("message", getIntent().getStringExtra("IN_SHARE_MESSAGE") == null ? "" : getIntent().getStringExtra("IN_SHARE_MESSAGE")); Request.Callback callback = new Request.Callback() { public void onCompleted(Response response) { isSharingData = false; lnrPbr.setVisibility(View.GONE); FacebookRequestError error = response.getError(); if (error != null) { IjoomerUtilities.getCustomOkDialog(getString(R.string.facebook_share_title), error.getErrorMessage(), getString(R.string.ok), R.layout.ijoomer_ok_dialog, new CustomAlertNeutral() { @Override public void NeutralMethod() { finish(); } }); } else { IjoomerUtilities.getCustomOkDialog(getString(R.string.facebook_share_title), getString(R.string.facebook_share_success), getString(R.string.ok), R.layout.ijoomer_ok_dialog, new CustomAlertNeutral() { @Override public void NeutralMethod() { finish(); } }); } } }; Request request = new Request(Session.getActiveSession(), "me/feed", postParams, HttpMethod.POST, callback); RequestAsyncTask task = new RequestAsyncTask(request); task.execute(); } } 
+1
source

Refer to this guide.

http://www.androidhive.info/2012/03/android-facebook-connect-tutorial/

 public void postToWall() { // post on user wall. facebook.dialog(this, "feed", new DialogListener() { @Override public void onFacebookError(FacebookError e) { } @Override public void onError(DialogError e) { } @Override public void onComplete(Bundle values) { } @Override public void onCancel() { } }); } 
0
source

Source: https://habr.com/ru/post/1501244/


All Articles