我已经解析了从 web 服务获得的数据,当我单击需要在 facebook 上共享该项目内容的详细活动页面所需的任何列表项时,它会显示在列表视图中。我尝试使用以下代码,但无法在 facebook 墙上共享数据。有人可以帮我解决这个问题吗?答案将被应用
详细活动
public class Singlemenuitem extends Activity {
// Your Facebook APP ID
private static String APP_ID = "308180782571605"; // 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;
static String TAG_URL = "url";
public String description,title;
// JSON node keys
static final String TAG_TITLE = "title";
static final String TAG_DATE = "date";
static final String TAG_NAME = "name";
static final String TAG_CONTENT = "content";
LinearLayout line1,line2,line3;
Button btnShare;
Button btnInvite;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_list_item);
// getting intent data
Intent in = getIntent();
final String url1 = in.getStringExtra(TAG_URL);
ImageView imgv = (ImageView) findViewById(R.id.imgdesc);
ImageLoader imageLoader = new ImageLoader(getApplicationContext());
imageLoader.DisplayImage(url1, imgv);
// Get JSON values from previous intent
final String title = in.getStringExtra(TAG_TITLE);
String date = in.getStringExtra(TAG_DATE);
String name = in.getStringExtra(TAG_NAME);
final String content = in.getStringExtra(TAG_CONTENT);
System.out.println("bool " +title +" "+date+" "+name +" " +content);
// Displaying all values on the screen
TextView lblName = (TextView) findViewById(R.id.name_label);
TextView lblCost = (TextView) findViewById(R.id.email_label);
TextView lblDesc = (TextView) findViewById(R.id.mobile_label);
TextView lblCont = (TextView) findViewById(R.id.content_label);
lblName.setText(title);
lblCost.setText(date);
lblDesc.setText(name);
lblCont.setText(content);
//share
ImageView facebook11=(ImageView) findViewById(R.id.facebook);
facebook11.setOnClickListener(new View.OnClickListener() {
//@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("Image Button", "button Clicked");
loginToFacebook();
if (facebook.isSessionValid()) {
postToWall();
}
}
});
}
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);
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this, new String[] { "feed" }, new DialogListener() {
public void onCancel() {
// Function to handle cancel event
}
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
postToWall();
}
public void onError(DialogError error) {
// Function to handle error
}
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);
}
private void postToWall() {
Bundle parameters = new Bundle();
parameters.putString("name", "Facebook SDK for Android");
//parameters.putString("title", lblName.getText().toString());
// parameters.putString("title", TAG_TITLE);
facebook.dialog(Singlemenuitem.this, "title", parameters, new DialogListener() {
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
}
public void onCancel() {
// TODO Auto-generated method stub
}
});
}}