Reputation: 1817
I am using android facebook api for publishing on users feed.
Login is working successfully, but the function publishstory is not working. I have the code below.
private void publishStory() {
Session session = Session.getActiveSession();
if (session != null){
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("name", "Facebook SDK for Android");
postParams.putString("caption", "Build great social apps and get more installs.");
postParams.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
postParams.putString("link", "https://developers.facebook.com/android");
postParams.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
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("error",
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(FacebookActivity.this.getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(FacebookActivity.this
.getApplicationContext(),
postId,
Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
the problem is it executes till line
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
and then comes out of the function on return without showing any popup. Any ideas?
Upvotes: 1
Views: 1153
Reputation: 1817
Return must be called only for fragment activity I was doing it in a normal activity which created the issue.
Upvotes: 0
Reputation: 2454
As you showed the code call the requestNewPublishPermissions()
when the access token is found without the necessary permissions.
But in order to complete the action after the request you have to define the Session.StatusCallback
.
private static Session.StatusCallback sessionCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
Log.i(TAG, "callback");
if (exception == null) {
if (pendingPublishAction && state.isOpened()) {
pendingPublishAction = false;
//do your post action;
}
}
else{
//handle exception
}
}
};
However, from what you said, it seemed that not even the dialog for the new permissions is showed. Did you implement the onActivityResult
like this?
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session session = Session.getActiveSession();
if (session != null) {
session.onActivityResult(this, requestCode, resultCode, data);
}
}
If you did so there must have been some other kind of error during the authentication phase, in this case logcat should show something.
Upvotes: 0