简体   繁体   中英

facebook share image is not showing on facebook via android app

I am new to facebook integration, i've been working on this several days now and i believe i will be able to fix this. My problem is, the image i attached for share dialog is not showing on facebook.

在此处输入图片说明

and here is my code:

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();

}

Using the Feed Dialog or Feed Graph API you can not pass the image data in picture . So you should provide a url instead of data.

Just a trick- you can first upload a picture using /photos where you can use the image data, then you can use this image url into the feed.

Hop it help. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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