简体   繁体   English

Android Facebook SDK v4 LikeView问题

[英]Android Facebook SDK v4 LikeView issue

I'm trying to implement the Facebook "Like Button" in my Android app. 我正试图在我的Android应用程序中实现Facebook“Like Button”。 Before I was using the Facebook SDK v3 where you would set up the LikeView and then call likeView.handleOnActivityResult(context, requestCode, resultCode, data) inside of onActivityResult(); 在我使用Facebook SDK v3之前,您将在其中设置LikeView,然后在onActivityResult()中调用likeView.handleOnActivityResult(context,requestCode,resultCode,data); This would change the button so that after the page was "liked" it would show "Liked" and the number of people that also like the page. 这将改变按钮,以便在页面被“喜欢”之后它将显示“喜欢”以及也喜欢该页面的人数。

Now, I'm using the Facebook SDK v4 because v3 is now deprecated. 现在,我正在使用Facebook SDK v4,因为现在不推荐使用v3。 In this version, I do not see any documentation or anyway to have this same type of functionality for the "like" button. 在这个版本中,我没有看到任何文档或者无论如何都没有为“喜欢”按钮提供相同类型的功能。 It no longer has the likeView.handlePnActivityResult method that v3 had. 它不再具有v3具有的likeView.handlePnActivityResult方法。 Now when the user hits the "like" button and likes the page, it doesn't change the state of the button. 现在,当用户点击“喜欢”按钮并喜欢该页面时,它不会改变按钮的状态。

Does anyone know how to solve this issue so that it will have the same functionality as the LikeView in the Facebook SDK v3? 有谁知道如何解决这个问题,以便它将具有与Facebook SDK v3中的LikeView相同的功能?

Here is the code of what I'm doing: 这是我正在做的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Initialize FaceBook SDK
    FacebookSdk.sdkInitialize(this);

    setContentView(R.layout.activity_about);

    // Set up ActionBar
    actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    terms = (LinearLayout) findViewById(R.id.terms_holder);
    privacyPolicy = (LinearLayout) findViewById(R.id.privacy_policy_holder);
    share = (LinearLayout) findViewById(R.id.social_media_holder);
    environmentButton = (Button) findViewById(R.id.environment_change);
    likeView = (LikeView) findViewById(R.id.like_view);

    likeView.setObjectIdAndType("##############", LikeView.ObjectType.PAGE);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // In the old Facebook SDK this is where it would change the like button to "liked 2,038" but this code is deprecated now apparently
    // likeView.handleOnActivityResult(this, requestCode, resultCode, data);
}

And here is my XML: 这是我的XML:

<LinearLayout
android:id="@+id/social_media_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="onClick" >


<com.facebook.share.widget.LikeView
    android:id="@+id/like_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="10dp" />           


<TextView
    android:id="@+id/post_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="5dp"
    android:text="@string/post_about_us"
    android:textSize="20dp"
    android:textColor="@color/dark_grey" />

Guardanis's answer is correct (Question's comment section). Guardanis的回答是正确的(问题的评论部分)。 But this is the code for it ( I used). 但这是它的代码(我用过)。

in onCreate(...) 在onCreate(...)

callbackManager = CallbackManager.Factory.create();

in onActivityResult(...) 在onActivityResult(...)

 callbackManager.onActivityResult(requestCode, resultCode, data);

Native Like Button: The Native Like Button, designed for mobile apps, will no longer be supported starting with Facebook SDK version 4.28 and above. Native Like Button:从Facebook SDK版本4.28及更高版本开始,将不再支持专为移动应用程序设计的Native Like Button。 Previous versions of the SDK can still use the Native Like Button, but starting 2/6, the Native Like Button will no longer be supported. 以前版本的SDK仍然可以使用Native Like按钮,但从2/6开始,将不再支持Native Like按钮。 After 2/6, the dialogs for Native Like will no longer appear and taps on any native like button will result in no action. 2/6之后,Native Like的对话框将不再出现,点击任何原生状按钮将导致无法执行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM