壹、前置確認
1.
如果要從APP將訊息貼到使用者的塗鴉牆,首先請在Manifest檔案中確認第一次設定Facebook SDK時的ContentProvider標籤是否有存在,如果沒有的話請加入
i.開啟AndroidManifest.xml檔,確認這行有無輸入
2.新增按鈕
i.開啟Activity_main.xml(Layout檔),增加以下程式碼
**Like Button
<com.facebook.share.widget.LikeView
android:id="@+id/likeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/login_button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
**Share Button
<com.facebook.share.widget.ShareButton
android:id="@+id/shareButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/likeView"
android:layout_marginTop="30dp" />
貳、程式撰寫
1.Like Part
i.打開Java主程式中的MainActivity.java,輸入以下程式碼(在onCreate下)
**網址部分請換上想按讚的網址**
LikeView likeView = (LikeView)findViewById(R.id.likeView);
likeView.setLikeViewStyle(LikeView.Style.STANDARD);
likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
likeView.setObjectIdAndType("https://www.facebook.com/viaalto/?ref=ts&fref=ts",LikeView.ObjectType.OPEN_GRAPH);
2.Share Part
i.分享連結中會包含以下屬性
contentURL:分享的連結
contentTitle:代表連結中的內容標題
imageURL:顯示在貼文上的縮圖圖像網址
contentDescriptipn:內容說明,2~4句
ii.打開Java主程式中的MainActivity.java,輸入以下程式碼(在onCreate下)
**於各段字串部分上面有制式規格,請依自況填寫**
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://www.facebook.com/viaalto/?ref=ts&fref=ts"))
.setContentTitle("Alto")
.setContentDescription("Alto 是皮革設計品牌")
.build();
ShareButton shareButton = (ShareButton)findViewById(R.id.fb_share_button);
shareButton.setShareContent(content);
參、程式執行
1.初始介面
3.Share介面
4.測試結果
Finish~~v( ̄︶ ̄)y







沒有留言:
張貼留言