我是facebook整合新手,我已经在这几天工作了,我相信我能解决这个问题。我的问题是,我在Facebook上没有显示我为共享对话框附加的图像。
这是我的代码:
public class ViewPagerAdapter extends PagerAdapter {
Context context;
String[] rank;
String[] country;
String[] population;
int[] bookCover;
LayoutInflater inflater;
@覆盖 public Object instantiateItem(ViewGroup容器,final int position){
final PdfHandler pdf = new PdfHandler(context);
final int pdfPos = position;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.viewpager_item, container, false);
ImageView imgflag = (ImageView) itemView.findViewById(R.id.flag);
// Capture position and set to the ImageView
//imgflag.setScaleType(ScaleType.FIT_XY);
imgflag.setImageResource(bookCover[position]);
// Add viewpager_item.xml to ViefeewPager
((ViewPager) container).addView(itemView);
imgflag.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int data = bookCover[position];
shareImage(data);
}
});
return itemView;
}
public void shareImage(int data) {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putInt("picture", data );
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(context,
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(context,
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(context,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(context,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(context,
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
答案 0 :(得分:0)
使用Feed对话框或Feed Graph API,您无法在picture
中传递图像数据。所以你应该提供一个网址而不是数据。
只是一个技巧 - 您可以先使用/photos
上传图片,然后您可以使用图片数据,然后就可以将此图片网址用于Feed。
随便帮忙。祝你好运!