Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android与Facebook SharePhotoContent共享图像URL_Android_Facebook_Facebook Sdk 4.0_Android Sharing - Fatal编程技术网

Android与Facebook SharePhotoContent共享图像URL

Android与Facebook SharePhotoContent共享图像URL,android,facebook,facebook-sdk-4.0,android-sharing,Android,Facebook,Facebook Sdk 4.0,Android Sharing,我正在尝试在新的SDK中使用Facebook的新SharePhoto和SharePhotoContent类共享一张照片。 我想使用图像URL而不是本地存储的图像 我能够使用本地存储的绘图资源共享图像: Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.carrots); SharePhoto photo = new SharePhoto.Builder() .set

我正在尝试在新的SDK中使用Facebook的新SharePhoto和SharePhotoContent类共享一张照片。 我想使用图像URL而不是本地存储的图像

我能够使用本地存储的绘图资源共享图像:

Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.carrots);

SharePhoto photo = new SharePhoto.Builder()
                   .setImageBitmap(image)
                   .build();

SharePhotoContent content = new SharePhotoContent.Builder()
                                .addPhoto(photo)
                                .build();

shareDialog.show(content);
但当我尝试使用图像URL时:

SharePhoto photo = new SharePhoto.Builder()
                       .setImageUrl(Uri.parse("http://s3-ak.buzzfed.com/static/images/public/verticals/food-title.png?v=201504021353"))
                       .build();
我看到的只是Facebook shareDialog中的一个空白帖子

有没有其他人试过这个并让它起作用


非常感谢

如果您使用的是链接而不是本地图像,则必须从


如果要共享图像的URL,则应使用
sharelinkcontent
:这是我的代码,它可以工作,但没有标题或说明,只有图像URL:


我所做的是下载图像并从服务器获取位图,然后发布到FB:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FacebookSdk.sdkInitialize(getApplicationContext());

    Button btn = (Button)findViewById(R.id.btn_share);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getImage();
        }
    });
}

private void getImage(){
    new DownloadImgTask().execute("http://url.com/1.jpg");
}

private void postFB(Bitmap bm){
    SharePhoto photo = new SharePhoto.Builder().setBitmap(bm).build();
    SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
    ShareDialog dialog = new ShareDialog(this);
    if (dialog.canShow(SharePhotoContent.class)){
        dialog.show(content);
    }
    else{
        Log.d("Activity", "you cannot share photos :(");
    }

}

private class DownloadImgTask extends AsyncTask<String, Void, Bitmap>{

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap bm = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            bm = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return bm;
    }

    protected void onPostExecute(Bitmap result) {
        postFB(result);
    }
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sdkinInitialize(getApplicationContext());
按钮btn=(按钮)findViewById(R.id.btn\U共享);
btn.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
getImage();
}
});
}
私有void getImage(){
新建下载IMGTASK()。执行(“http://url.com/1.jpg");
}
私有void postFB(位图bm){
SharePhoto photo=new SharePhoto.Builder().setBitmap(bm.build();
SharePhotoContent内容=新建SharePhotoContent.Builder().addPhoto(photo.build();
ShareDialog=新建ShareDialog(此);
if(dialog.canShow(SharePhotoContent.class)){
对话框。显示(内容);
}
否则{
Log.d(“活动”,“您不能共享照片:(”);
}
}
私有类下载IMGTASK扩展异步任务{
受保护位图doInBackground(字符串…URL){
字符串urldisplay=url[0];
位图bm=null;
试一试{
InputStream in=newjava.net.URL(urldisplay.openStream();
bm=BitmapFactory.decodeStream(in);
}捕获(例外e){
Log.e(“Error”,e.getMessage());
e、 printStackTrace();
}
返回bm;
}
受保护的void onPostExecute(位图结果){
postFB(结果);
}
}

所以我不能像使用位图那样简单地使用url来显示照片?如果不是,那么SharePhoto模型中的
setImageUrl
函数的意义是什么?您可以尝试使用SharePhoto.Builder()photo=new SharePhoto.Builder()尝试的是“SharePhoto photo”而不是“SharePhoto.Builder photo”我认为这行不通。在
SharePhotoContent
builder中,我必须添加一个SharePhoto对象,而不是SharePhoto.builder对象。由于setContentTitle、setContentDescription和setContentUrl已被弃用,它将不再起作用。有趣的是,当我使用您的确切代码创建SharePhoto时,我看到了以下错误:。您确定e Uri.parse实际上是在返回一个非空Uri?有时是Uri.parse()方法将无声地失败,只会给你一个null。@MingLi我在测试期间根本没有看到该错误消息。我确信Uri是非null的。你在上面的帖子中使用的是准确的url吗?如果是这样,那么你应该用一个小样本应用程序作为zip在上提交一个bug,然后我们可以看看发生了什么。@MingLi我正在使用这个示例act url。由于我的工作期限很紧,所以我需要花一点时间来归档该错误。因此,作为一种解决方法,我只是下载了该图像,然后将其作为位图共享。但是谢谢你的帮助!你解决了你的问题吗?我也有同样的问题。啊,这也是我最后要做的
    ShareLinkContent linkContent = new ShareLinkContent.Builder()
            .setContentTitle("Shared from nearbyme application")
            .setContentDescription("This is a wonderful place")
            .setContentUrl(Uri.parse("http://www.villathena.com/images/nearby/thumbs/le-bus-bleu-private-tours.jpg"))
            .setImageUrl(Uri.parse("http://www.villathena.com/images/nearby/thumbs/le-bus-bleu-private-tours.jpg"))
            .build();
      shareDialog.show(content);
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FacebookSdk.sdkInitialize(getApplicationContext());

    Button btn = (Button)findViewById(R.id.btn_share);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getImage();
        }
    });
}

private void getImage(){
    new DownloadImgTask().execute("http://url.com/1.jpg");
}

private void postFB(Bitmap bm){
    SharePhoto photo = new SharePhoto.Builder().setBitmap(bm).build();
    SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
    ShareDialog dialog = new ShareDialog(this);
    if (dialog.canShow(SharePhotoContent.class)){
        dialog.show(content);
    }
    else{
        Log.d("Activity", "you cannot share photos :(");
    }

}

private class DownloadImgTask extends AsyncTask<String, Void, Bitmap>{

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap bm = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            bm = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return bm;
    }

    protected void onPostExecute(Bitmap result) {
        postFB(result);
    }
}