我做了一個關於在android中使用facebook sdk將我的狀態(包括鏈接,照片,視頻)發佈到我的牆上的示例。 按照此Facebook的教程鏈接:facebook startup tutorial我登錄並通過ShareLinkContent類成功發佈鏈接狀態。但是我無法安裝官方安卓平板應用程序,無法分享照片(SharePhotoContent類)和視頻(ShareVideoContent類)。本教程不要求他們的應用程序必須先安裝,但我不能使用我的示例應用程序發佈我的照片,沒有安裝他們的應用程序的視頻。分享媒體內容使用facebook sdk 4.x +
ShareDialog.canShow(ShareLinkContent.class)
總是返回true,無論他們的Facebook應用程序安裝
ShareDialog.canShow(SharePhotoContent.class)
ShareDialog.canShow(ShareVideoContent.class)
只返回true,如果他們的Facebook應用程序安裝
我的代碼共享照片:
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 :(");
}
}
代碼共享視頻:
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 :(");
}
}
我已經設置了我的應用程序的權限:「publish_actions」。
我錯過了什麼嗎?或者Trully我必須先安裝Facebook應用程序,然後才能使用他們提供的sdk開發我的應用程序(incase post photo,video)?
和facebook原生必須安裝在手機上是沒有必要的.....如果能夠共享,然後檢查你的位圖設置它在一些圖像視圖。 –
是的。我已經初始化Facebook的sdk並設置我的權限,如果沒有,它會重新登錄發佈權限。 ShareLinkContent類始終允許我將狀態發佈爲url,但是我想使用SharePhotoContent和ShareVideoContent發佈我的本地照片和視頻,我已經檢查並且只在我安裝了Facebook原生應用時才工作(它將啓動Facebook應用,如發送意圖,其中包含額外的本地照片uri,視頻uri ....) – LuongPham
你試過ShareApi.show(mContext,content1); –