我必须在 android 应用程序中与 facebook 集成。
在这里,我必须单击按钮意味着打开了 fb 登录页面。如果我必须输入正确的登录页面,则意味着打开了贴墙。
在这里我必须写一些文本意味着它已成功发布到 fb 墙上。但我希望在这里传递字符串值。该字符串值显示在该编辑文本框上也发布在墙上。我该怎么办?
我使用以下代码:
public class AndroidFacebookConnectActivity extends Activity {
// Your Facebook APP ID
private static String APP_ID = "xxxxx"; // Replace with your App ID
// Instance of Facebook Class
private Facebook facebook = new Facebook(APP_ID);
private AsyncFacebookRunner mAsyncRunner;
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
Button btnFbLogin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnFbLogin = (Button) findViewById(R.id.btn_fblogin);
mAsyncRunner = new AsyncFacebookRunner(facebook);
btnFbLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Image Button", "button Clicked");
loginToFacebook();
}
});
}
public void loginToFacebook() {
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
btnFbLogin.setVisibility(View.INVISIBLE);
postToWall();
Log.d("FB Sessions", "" + facebook.isSessionValid());
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this,
new String[] { "email", "publish_stream" },
new DialogListener() {
@Override
public void onCancel() {
// Function to handle cancel event
}
@Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",
facebook.getAccessToken());
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
btnFbLogin.setVisibility(View.INVISIBLE);
postToWall();
}
@Override
public void onError(DialogError error) {
// Function to handle error
}
@Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
}
});
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
public void postToWall() {
// post on user's wall.
facebook.dialog(this, "feed", new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
}
@Override
public void onError(DialogError e) {
}
@Override
public void onComplete(Bundle values) {
String sh="Krish";
Bundle params = new Bundle();
params.putString("message", sh);
params.putString("name", sh);
}
@Override
public void onCancel() {
}
});
}}
在这里我如何发布字符串 sh="Krish"; FB 墙上的值。我如何在 FB 文本上显示这些 Krish 值。请给我一些建议...
编辑:
这是我更新的完整代码:
@Override
public void onComplete(Bundle values) {
String sh="Krish";
Bundle parameters = new Bundle();
parameters.putString("caption",sh);
}
但现在也遇到了同样的错误。我该如何解决这些问题。请帮助我。
在这里,我必须写文本嗨。这些嗨已成功发布。但我希望动态地在该编辑文本框中显示Krish 。我该怎么办????