0
通過Facebook SDK我要分享一條消息給Facebook。我可以成功地分享我的消息,但是我沒有看到任何登錄和發佈消息的對話框。當我點擊我的分享按鈕時,我的消息將被髮布到Facebook上,而沒有對話界面。那麼,如何顯示對話框並讓我的用戶點擊發布按鈕?Android,當我發佈消息給Facebook時,Dialog界面不顯示?
這是MT代碼:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Try to create activity...");
mFacebook = new Facebook(FACEBOOK_APPID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
if(!restoreCredentials(mFacebook)) {
Log.i(TAG, "Try to get token...");
mFacebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
postFacebookMessage();
}
//
private void postFacebookMessage() {
Log.i(TAG, "Try to post message");
token = mFacebook.getAccessToken();
Log.i("token", "" + token);
Bundle parameters = new Bundle();
parameters.putString("access_token", token);
parameters.putString("message", "Text is test message.");
parameters.putString("name", "Chef Astro");
parameters.putString("link", "http://www.astrogempak.com.my");
parameters.putString("caption", "Caption");
parameters.putString("description", message);
parameters.putString("picture","http://a1.mzstatic.com/us/r30/Purple/v4/2d/7d/c3/2d7dc3ed-9e32-cd7b-adba-2a31637a8cf0/mzl.toeyydsk.175x175-75.jpg");
mAsyncRunner.request("me/feed", parameters, "POST", new WallPostRequestListener(), null);
}
//
class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
saveCredentials(mFacebook);
Log.i(TAG, "Credentials saved.");
}
public void onFacebookError(FacebookError error) {
showToast("Authentication with Facebook failed!");
}
public void onError(DialogError error) {
showToast("Authentication with Facebook failed!");
}
public void onCancel() {
showToast("Authentication with Facebook cancelled!");
}
}
//
public boolean saveCredentials(Facebook facebook) {
Editor editor = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.putString(TOKEN, facebook.getAccessToken());
editor.putLong(EXPIRES, facebook.getAccessExpires());
return editor.commit();
}
public boolean restoreCredentials(Facebook facebook) {
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE);
facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
return facebook.isSessionValid();
}
//
public class WallPostRequestListener extends BaseRequestListener {
public void onComplete(final String response, final Object state) {
Log.d("Facebook-Example", "Got response: " + response);
String message = "<empty>";
try {
JSONObject json = Util.parseJson(response);
message = json.getString("message");
} catch (JSONException e) {
Log.w("Facebook-Example", "JSON Error in response");
} catch (FacebookError e) {
Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
}
final String text = "Your Wall Post: " + message;
FacebookActivity.this.runOnUiThread(new Runnable() {
public void run() {
Log.d(TAG, text);
}
});
closeActivity();
}
}
在上面的代碼中,我希望當對話框顯示用戶可以寫他/她在文本框中的建議,我在這裏得到它。
謝謝,親愛的Rishabah。是的,我閱讀了該文檔,我的代碼基於其SDK中的示例。但是,我沒有顯示對話界面。 – Hesam
有些手機不顯示對話框,這是在facebook和bug中的錯誤sdk.kindly使用其他手機來測試你的代碼。 – yokees
謝謝親愛的Rishabh。其實我用mAsyncRunner.request(...)重放mAsyncRunner.request(...)行解決了這個問題,但我還有另一個問題。請參閱我的下一個問題:http://stackoverflow.com/questions/12453347/android-how-to-fit-message-in-facebook-dialog – Hesam