我有以下代码使用FB sdk发布到FB。第一次当我点击按钮发布时,它会打开此活动并尝试进行身份验证,我会收到FB页面,说“您还没有登录”。如果我按回并尝试再次发布,我将获得登录页面以输入凭据并且帖子成功。该问题仅在安装应用程序后首次出现。 请帮助解决这个问题
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("FAceBook","create instance");
facebook = new Facebook(APP_ID);
facebook.authorize(FaceBookShareActivity.this, PERMISSIONS,Facebook.FORCE_DIALOG_AUTH,
new DialogListener() {
@Override
public void onComplete(Bundle values) {
try {
Log.i("FAceBook","DialogListener");
Bundle parameters = new Bundle();
parameters.putString("message", "msg");
String response = facebook.request("me/feed", parameters,
"POST");
Log.d("fbproblem", "got response: " + response);
if (response == null || response.equals("")
|| response.contains("error")) {
Log.d("Login failed", "RETRY");
} else {
Log.d("fbproblem",
"Message posted to your facebook wall!");
Toast.makeText(getApplicationContext(),
"Message posted to your facebook wall!",
Toast.LENGTH_LONG).show();
// facebook.logout(MainActivity.this);
}
} catch (Exception e) {
// finish();
Log.d("fbproblem", e.getMessage());
}
Log.d("fbproblem", "SUCCESS");
finish();
}
@Override
public void onFacebookError(FacebookError error) {
Log.d("fbproblem", error.getMessage());
// finish();
}
@Override
public void onError(DialogError e) {
Log.d("fbproblem", e.getMessage());
// finish();
}
@Override
public void onCancel() {
Log.d("fbproblem", "");
// finish();
}
});
Log.i("FAceBook","Call authorise");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
Log.i("FAceBook","authorizeCallback called");
} catch (Exception e) {
Log.d("fbproblem", e.getMessage());
Toast.makeText(getApplicationContext(),
"Something goes wrong Try again Later!!", Toast.LENGTH_LONG)
.show();
}
}