0

我需要在我的小部件应用程序中实现 Facebook Like 功能。为此,我正在尝试从 SDK 实现 Facebook LikeView compile 'com.facebook.android:facebook-android-sdk:4.0.1'。但不幸的是,我无法使用此视图,因为小部件使用 RemoteViews。因此,我完全坚持使用我应该遵循的方法来实现Facebook LikeGraph api因为缺少用于此目的的文档。我正在发布我用于 Facebook 的代码,如下所示

MainActivity.java

public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LikeView likeView = (LikeView) findViewById(R.id.likeView);
        likeView.setLikeViewStyle(LikeView.Style.STANDARD);
        likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);

        likeView.setObjectIdAndType(
                "https://www.facebook.com/JavaDigest/",
                LikeView.ObjectType.OPEN_GRAPH);

    }

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.facebooklike.MainActivity">

    <com.facebook.share.widget.LikeView
        android:id="@+id/likeView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
</RelativeLayout>

AndroidManifest.xml

<meta-data
        android:name="com.facebook.sdk.ApplicationName"
        android:value="@string/app_name" />
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/app_id" />

    <provider
        android:name="com.facebook.FacebookContentProvider"
        android:authorities="com.facebook.app.FacebookContentProvider2XXXXXXXXXXX85"
        android:exported="true" />

任何对我很有帮助的帮助和替代解决方案。提前致谢。

4

1 回答 1

0

我还实现了一个类似 facebook 的功能,并且它也成功地与 LikeView.ObjectType.OPEN_GRAPH 一起为我工作。

这是带有详细说明的代码

在 MainActivity 中定义它

CallbackManager callbackManager;
LikeView likeView;

MainActivity onCreate 方法

callbackManager = CallbackManager.Factory.create();
likeView = (LikeView) findViewById(R.id.likeview);

likeView.setLikeViewStyle(LikeView.Style.BOX_COUNT);
likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
likeView.setObjectIdAndType(
            "http://shareitexampleapp.parseapp.com/photo1/",
             LikeView.ObjectType.OPEN_GRAPH);

在您的 Mainactivity 添加 onActivityResult 方法

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

AndroidManifest.xml

 <meta-data
     android:name="com.facebook.sdk.ApplicationId"
     android:value="@string/FacebookId" />

并从清单中删除提供者

//Remove this provider

<provider
     android:name="com.facebook.FacebookContentProvider"
     android:authorities="com.facebook.app.FacebookContentProvider2XXXXXXXXXXX85"
     android:exported="true" />
于 2016-05-27T12:09:18.973 回答