Unable to share video's URL on Facebook via An

2019-08-30 03:14发布

问题:

I need to share URL on video resource programmatically. Example of URL is http://flash.video.worldnow.com/kold/KOLD_20110714204221200AA.mp4

I use Intent.ACTION_SEND for it:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Test subject");
sendIntent.putExtra(Intent.EXTRA_TEXT, "http://flash.video.worldnow.com/kold/KOLD_20110714204221200AA.mp4");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent,
                "Share URL"));

Facebook android application can't handle the URL and shows following error:

"flash objects must have the 'swfsrc' and 'imgsrc' attributes"

How to avoid the error? How to put required attributes into "text/plain" message?

回答1:

After several hours of trying to find out how to make it work for uploading and sharing video on facebook, youtube, instagram and whatsapp. this is the code that worked for me. Uploading recorded video from your application to social media applications

try using ContentValues when dealing with videos and specifying MediaStore.Video.Media.Data in the content.

ContentValues content = new ContentValues(4);
        content.put(Video.VideoColumns.DATE_ADDED,
        System.currentTimeMillis() / 1000);
        content.put(Video.Media.MIME_TYPE, "video/mp4");
        content.put(MediaStore.Video.Media.DATA, "your_path_to_video");
        ContentResolver resolver = getBaseContext().getContentResolver();
        Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);

        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("video/*");
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title");
        sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
        startActivity(Intent.createChooser(sharingIntent,"share:")); `


回答2:

I've looked at Facebook application sources (ShareLinkActivity) and didn't found any possibility to add required fields to share request. Content of intent extra parameter Intent.EXTRA_TEXT only is used.



回答3:

Have a look at this page here. It looks like it wants the swfsrc and imgsrc encoded in a JSON-encoded array. Hope this helps.



回答4:

I searched this for almost 7 hours, following is the only solution that worked for me perfectly .

 File filePath = filesList[position]; 
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_TEXT, "Text");
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filesList[position].getAbsolutePath())));  //optional//use this when you want to send an image
            shareIntent.setType("video/mp4");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(shareIntent, "send"));