在通过Facebook分享我的应用程序时,它工作正常但在帖子上显示“只有我”。我希望所有朋友都能看到帖子。以下是我正在使用的代码段:
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
在创建方法上:
com.facebook.Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
com.facebook.Session session = com.facebook.Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = com.facebook.Session.restoreSession(this, null, statusCallback, savedInstanceState);
}
if (session == null) {
session = new com.facebook.Session(this);
}
com.facebook.Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new com.facebook.Session.OpenRequest(this).setCallback(statusCallback));
session.openForPublish(new Session.OpenRequest(this)
.setCallback(statusCallback)
.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO)
.setPermissions(Arrays.asList("publish_actions")));
}
我正在使用foolowing代码发布故事
private void uploadStoryUsingFacebook() {
// Toast.makeText(HomeScreenActivity.this, "NOw we can post story !!!",2000).show();
// Check for publish permissions
Session session = Session.getActiveSession();
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle params = new Bundle();
params.putString("name", "");
params.putString("link", "some link");
params.putString("picture", "some picture");
FeedDialogBuilder builder = new FeedDialogBuilder(HomeScreenActivity.this, Session.getActiveSession(), params);
builder.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error != null) {
}
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(HomeScreenActivity.this,"Posted story, id: "+postId,Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(HomeScreenActivity.this, "Publish cancelled",Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(HomeScreenActivity.this.getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(HomeScreenActivity.this.getApplicationContext(), "Error posting story",Toast.LENGTH_SHORT).show();
}
}
});
builder.build().show();
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}
有人可以指导我解决这个问题吗?
答案 0 :(得分:0)
试试这个 - &gt;