Android分享图片网址Facebook SharePhotoContent
我试图在新SDK中使用Facebook的新SharePhoto分享照片& SharePhotoContent类。 我想使用图片网址而不是本地存储的图片。Android分享图片网址Facebook SharePhotoContent
我能够使用本地存储的绘制资源共享的图像:
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);
但是当我尝试使用图片网址:
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中使用ShareDialog代替SharePhoto,从doc
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("title")
.setContentDescription("description")
.setContentUrl(Uri.parse("your link"))
.build();
因此,我不能只使用一个URL来显示一张像它与位图一样的照片?如果不是,那么SharePhoto模型中的'setImageUrl'函数有什么意义? – 2015-04-03 05:41:01
你可以试试SharePhoto.Builder()photo = new SharePhoto.Builder() – 2015-04-03 06:00:53
是的,我试过了。这是在我的问题 – 2015-04-03 06:17:09
,那么你应该使用sharelinkcontent
:这是我的代码,它的工作,但没有一个标题或描述只是图像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);
我确实是下载图片,并从服务器获取的位图,然后发布到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);
}
}
是的,这也是我最终做的 – 2015-04-28 03:51:14
有趣的是,当我使用您的确切代码来创建SharePhoto时,我看到这个错误:http://i.imgur.com/O7TFGsM.jpg。你确定Uri.parse实际上是给你一个非空Uri吗?有时候,Uri.parse()方法会默默地失败,只是给你一个null。 – 2015-04-03 19:56:02
@MingLi我在测试过程中根本没有看到这个错误信息。我确信Uri是非空的。 – 2015-04-03 20:18:43
你在上面的帖子中使用了确切的网址吗?如果是这样,那么你应该在https://developers.facebook.com/bugs上用一个小样本应用程序作为zip文件提交bug,然后我们可以看看发生了什么。 – 2015-04-03 22:24:42