Share media content use facebook sdk 4.x +

I am doing an example about using facebook sdk in android to post my status (including link, photo, video) to my wall. Follow this link in facebook tutorial : facebook startup tutorial I have successfully registered link status on ShareLinkContent class. But I can't share photo (SharePhotoContent class) and video (ShareVideoContent class) without the official Android app installed. The tutorial doesn't require their app to be installed first, but I can't use my sample app to post my photo, video without their app.

ShareDialog.canShow(ShareLinkContent.class)

      

always returns true regardless of the installed facebook app

ShareDialog.canShow(SharePhotoContent.class)
ShareDialog.canShow(ShareVideoContent.class)

      

returns true only if facebook app is installed

My photo sharing code:

    public void sharePhoto() {
    Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    SharePhoto photo = new SharePhoto.Builder().setBitmap(image).build();
    SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
    ShareDialog dialog = new ShareDialog(this);
    if (ShareDialog.canShow(SharePhotoContent.class)){
        dialog.show(content);
    }
    else{
        Log.d("Activity", "you cannot share photos :(");
    }
}

      

Video sharing code:

   public void shareVideo() {
    Uri selectedVideo = Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Video" + "/fight.mp4");
    if (ShareDialog.canShow(ShareVideoContent.class)) {
        ShareVideo shareVideo = new ShareVideo.Builder().setLocalUrl(selectedVideo).build();
        ShareVideoContent shareVideoContent = new ShareVideoContent.Builder()
                .setVideo(shareVideo)
                .setContentTitle("Video Title")
                .setContentDescription("Video description")
                .build();
        ShareDialog dialog = new ShareDialog(this);
        dialog.show(shareVideoContent);
    } else{
        Log.d("Activity", "you cannot share videos :(");
    }
}

      

I have set permission for my application: "publish_actions".

Did I miss something? Or Trully do I have to install the facebook app before I can develop the app using their provided sdk (expose photo, video)?

+3


source to share


1 answer


You are initializing the Facebook SDK ........ if yes then ask permission like this

Set<String> permissions = AccessToken.getCurrentAccessToken()
        .getPermissions();

final List<String> PUBLISH_PERMISSIONS = Arrays
        .asList("publish_actions");
if (!permissions.containsAll(PUBLISH_PERMISSIONS)) {

    // pendingPublishReauthorization = true;
    LoginManager.getInstance().logInWithPublishPermissions(this,
            PUBLISH_PERMISSIONS);
    return;
}

      



then check if you can post network image ...... like this

 ShareLinkContent content1 = new ShareLinkContent.Builder()
            .setContentUrl(
                    Uri.parse("https://play.google.com/store/apps/details?id=pk.wisesolutions.naatcollection"))
            .setContentTitle(final_messgae)
            .setContentDescription(
                    "Naat Collection App - listen to hundreds of naats free")
            .setImageUrl(
                    Uri.parse("http://apps.wisesolutions.pk/app/naatcollection/images/logo_180x180.png"))
            .build();

    MessageDialog.show(mContext, content1);

      

0


source







All Articles