Like 按钮可用于为 Facebook 主页或任何 Open Graph 对象点赞,并可通过 URL 或 ID 引用。这是代码的样子。
文档 android facebook sdk
在您的 Activity 或 Fragment 的 onCreate 方法中,使用 UiLifecycleHelper 或调用 Settings.sdkInitialize:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, callback);
// if you don't want to use the UiLifecycleHelper, call sdkInitialize instead
// Settings.sdkInitialize(this);
...
然后设置 Like 按钮的对象 ID(可以是 URL 或 Facebook ID):
LikeView likeView = (LikeView) findViewById(R.id.like_view);
likeView.setObjectId("http://shareitexampleapp.parseapp.com/photo1/");
最后,在 onActivityResult 方法中再次调用 UiLifecycleHelper
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data, null);
// if you don't use the UiLifecycleHelper, call handleOnActivityResult on the LikeView instead
// LikeView.handleOnActivityResult(this, requestCode, resultCode, data);
...
