我正在开发一个应用程序,我正在做Facebook分享。我成功地分享了,但只有当我没有安装Facebook应用程序时。当我正在安装Facebook应用程序,并尝试共享然后它要求登录,因为我正在记录然后我得到以下对话框“我的应用程序想要访问您的公共个人资料和朋友列表”。当我点击“确定”按钮时,它正在执行某个过程并再次进入我的应用程序,但没有任何内容可以共享。 请帮我。 这是我的代码: -
public class BaseFbTwitterShareAppActivity extends Activity {
private UiLifecycleHelper uiHelper;
public Session.StatusCallback statusCallback = new SessionStatusCallback();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, statusCallback);
uiHelper.onCreate(savedInstanceState);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data,
new FacebookDialog.Callback() {
@Override
public void onError(FacebookDialog.PendingCall pendingCall,
Exception error, Bundle data) {
}
@Override
public void onComplete(
FacebookDialog.PendingCall pendingCall, Bundle data) {
// Log.i("Activity", "Success!");
}
});
}
@Override
protected void onResume() {
super.onResume();
uiHelper.onResume();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
private void shareApp() {
Bundle params = new Bundle();
params.putString("name", "aaa");
params.putString("caption",
"bbb");
params.putString("description", "Dummy data.");
params.putString("link", "https://www.facebook.com/xxx");
params.putString("picture",
"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/yyy.png");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this,
Session.getActiveSession(), params)).setOnCompleteListener(
new OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(BaseFbTwitterShareAppActivity.this, "Posted story, id: " + postId, Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(BaseFbTwitterShareAppActivity.this,
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(BaseFbTwitterShareAppActivity.this,
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
} else {
// Generic, ex: network error
Toast.makeText(BaseFbTwitterShareAppActivity.this,
"Error posting story", Toast.LENGTH_SHORT)
.show();
}
}
}).build();
feedDialog.show();
}
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
shareApp();
} else if (state.isClosed()) {
}
}
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state,
Exception exception) {
// Respond to session state changes, ex: updating the view
// shareApp();
try {
// Log.d("FB", "Access token = " + session.getAccessToken());
} catch (Exception ex) {
ex.printStackTrace();
}
onSessionStateChange(session, state, exception);
}
}
public void onFbButtonClick() {
Session mSession = Session.getActiveSession();
if (mSession == null) {
mSession = new Session(this);
}
if (!mSession.isOpened() && !mSession.isClosed()) {
mSession.openForPublish(new Session.OpenRequest(this)
.setPermissions(Arrays.asList("publish_actions"))
.setCallback(statusCallback));
} else {
Session.openActiveSession(this, true, statusCallback);
}
}
}
答案 0 :(得分:0)
我得到了答案,代码很完美,但我的HashKey不匹配。我不知道为什么它没有Facebook应用程序共享。但是当我把正确的密钥放在那时它在两种情况下共享。 - 当我有Facebook应用程序。 - 当我没有Facebook应用程序。