Slo*_*nho 8 sdk android facebook
我正试图在我的Android应用程序中实现Facebook"Like Button".在我使用Facebook SDK v3之前,您将在其中设置LikeView,然后在onActivityResult()中调用likeView.handleOnActivityResult(context,requestCode,resultCode,data); 这将改变按钮,以便在页面被"喜欢"之后它将显示"喜欢"以及也喜欢该页面的人数.
现在,我正在使用Facebook SDK v4,因为现在不推荐使用v3.在这个版本中,我没有看到任何文档或者无论如何都没有为"喜欢"按钮提供相同类型的功能.它不再具有v3具有的likeView.handlePnActivityResult方法.现在,当用户点击"喜欢"按钮并喜欢该页面时,它不会改变按钮的状态.
有谁知道如何解决这个问题,以便它将具有与Facebook SDK v3中的LikeView相同的功能?
这是我正在做的代码:
@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);
}
Run Code Online (Sandbox Code Playgroud)
这是我的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" />
Run Code Online (Sandbox Code Playgroud)
Guardanis的回答是正确的(问题的评论部分).但这是它的代码(我用过).
在onCreate(...)
callbackManager = CallbackManager.Factory.create();
Run Code Online (Sandbox Code Playgroud)
在onActivityResult(...)
callbackManager.onActivityResult(requestCode, resultCode, data);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2429 次 |
| 最近记录: |