简体   繁体   中英

Facebook shareDialog doesn't show anything

I'm trying to share some content's on facebook but i have a lot of problems. i've add the correct keyhash, and created the app on facebook and put it live. When i try to share something it seems good as you can see:

在此输入图像描述

But after i've clicked on post it's empty: 在此输入图像描述

It's a permission problem? i've read a lot about this on stack but i can't find an answer that works... That's the code :

public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) 
        {
            case R.id.action_share:         
                Intent intent2=new Intent(Intent.ACTION_SEND);
                intent2.setType("text/plain");
                intent2.putExtra(Intent.EXTRA_TEXT,"'"+ random + "'" + "\n"+"By Random Quotes"); 
                startActivity(Intent.createChooser(intent2, "Share via"));
                break;

                case R.id.randombut:
                     Frasi();

                case android.R.id.home:
                    Intent homeIntent = new Intent(this, MainActivity.class);
                    homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(homeIntent);
                break;

                case R.id.facebook:
                    FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
                    .setApplicationName("Random Quotes")
                    .setDescription(random)
                .setPicture("https://lh6.ggpht.com/1UJ89ho9pvVLPYS6NsFVQdb7KoQPALMhkw1w7DnNDqcfDYJ-tRxruaf2YLMLyqhnG_g=w300-rw")
                    .setLink("https://play.google.com/store/apps/details?id=com.techappstudios.randomquotes")
                    .build();
                    uiHelper.trackPendingDialogCall(shareDialog.present());

         }
        return true;
    }

I had a similar problem.

I fixed it by changing where the picture came from (don't ask me why this worked because I really don't know).

Instead of grabbing my picture URL from websites such as facebook or google play, I uploaded the picture to gethub. With gethub, the picture url ended in a .png. The picture, link and description posted as they were supposed to.

Give this a try. I hope it helps.

I think this related to permission, you need to request for publish_actions permission. For the first time facebook will ask for accept the new permission. Once you accepted, the sharedialog will show directly.

This is what I did, But the code i replace with your sharing info.

final Session activteSession  = Session.getActiveSession();
        if(!activteSession.isPermissionGranted("publish_actions")) {
            Session.getActiveSession().requestNewPublishPermissions(new Session.NewPermissionsRequest(this, "publish_actions"));
        }
        FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
                .setApplicationName("Random Quotes")
                .setDescription(random)
            .setPicture("https://lh6.ggpht.com/1UJ89ho9pvVLPYS6NsFVQdb7KoQPALMhkw1w7DnNDqcfDYJ-tRxruaf2YLMLyqhnG_g=w300-rw")
                .setLink("https://play.google.com/store/apps/details?id=com.techappstudios.randomquotes")
                .build();
                uiHelper.trackPendingDialogCall(shareDialog.present());
        mFacebookUIHelper.trackPendingDialogCall(shareDialog.present());

Hope this will help.

From the latest update of Facebook SDK, Facebook don't allow prefill text. So you can only share URL right now. This is not matter that you are using ShareDialog or Share Intent.

Please see below bug link for more details

https://developers.facebook.com/bugs/332619626816423

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