我必须在android应用程序中与facebook集成。
在这里我必须单击按钮意味着fb登录页面已打开。如果我必须输入正确的登录页面,则意味着打开了帖子到墙。
这里我要写一些文字意味着它成功发布到fb wall.But我希望在这里传递字符串值。该编辑文本框上显示的字符串值也发布在wall.how我可以吗? ?
我使用下面的代码:
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() {
}
});
}}
在这里我如何在FB wall上发布 String sh =“Krish”; 值。我可以在fb text上显示这些Krish值。请给我一些建议......
修改
这是我更新的完整代码:
@Override
public void onComplete(Bundle values) {
String sh="Krish";
Bundle parameters = new Bundle();
parameters.putString("caption",sh);
}
但现在我也得到同样的错误。我可以解决这些问题。请帮助我。
在这里我必须写文字嗨。这些嗨成功发布。但我希望动态地在该edittext框上显示 Krish 。我该怎么办? ???
答案 0 :(得分:0)
尝试将此添加到您的OnComplete
params.putString("caption",sh);
答案 1 :(得分:0)
您确定使用的是Facebook SDK 3吗?
根据这些方针:
private Facebook facebook = new Facebook(APP_ID);
private AsyncFacebookRunner mAsyncRunner;
我认为您使用的是旧SDK,因此弃用了许多方法。