繁体   English   中英

facebook 共享图像未通过 android 应用程序显示在 facebook 上

[英]facebook share image is not showing on facebook via android app

我是 facebook 集成的新手,我已经为此工作了几天,我相信我能够解决这个问题。 我的问题是,我为共享对话框附加的图像未显示在 facebook 上。

在此处输入图片说明

这是我的代码:

public class ViewPagerAdapter extends PagerAdapter {

Context context;
String[] rank;
String[] country;
String[] population;
int[] bookCover;
LayoutInflater inflater;

@Override public Object instantiateItem(ViewGroup container, 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();

}

使用饲料对话框或饲料图形API你不能传递的图像数据picture 所以你应该提供一个 url 而不是数据。

只是一个技巧 - 您可以首先使用/photos上传图片,您可以在其中使用图像数据,然后您可以将此图像网址用于提要。

跳它有帮助。 祝你好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM