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?