Android 应用程序中的 Facebook Like 按钮?

发布于 2024-12-08 17:29:43 字数 600 浏览 0 评论 0原文

还有其他一些老问题提出了类似的问题,但似乎没有任何明确的答案。自从提出这些问题以来已经过去了一段时间,所以我想知道是否有办法做到这一点?

查看 Facebook 的 Android SDK,这里有一些关于如何在墙上分享内容的示例,请发布图片到你的墙上,登录,注销等...但似乎没有任何关于添加一个简单的“喜欢”按钮...我希望能够向我的应用程序添加一个“喜欢”按钮(通过 ImageView或者可能是一个样式化的按钮),一旦点击 Facebook 就会加载授权登录对话框,然后请求您的许可来喜欢该应用程序。

好像他们那里会有什么东西……我只是没有看到它吗?

有些人建议制作一个与 HTML Facebook Like 按钮大小相同的小型 WebView,并将其集成到您的布局中。这样做的问题是,当用户单击 WebView 中的 Like 按钮时,它会想要打开一个 Javascript 窗口供用户登录 Facebook,但这个对话框几乎肯定不适合微小的 WebView。

是否有任何明确的方法可以在 Android 应用程序中添加 Facebook Like 按钮?

There are a few other old SO questions asking a similar question, but there doesn't seem to be any definitive answer for them. Some time has passed since those questions were asked, so I was wondering if there was a way to do this yet?

Looking at Facebook's Android SDK, there are examples on how to share things on your wall, post pictures to your wall, login, logout, etc... but it there doesn't appear to be anything about adding a simple Like button... I was expecting to be able to add a Like Button to my app (via a ImageView or maybe a styled Button), once clicked Facebook would load an authorization login dialog and then ask for your permission to Like the app.

It seems like something they would have in there... am I just not seeing it?

Some people have suggested making a tiny WebView that is the size of the HTML Facebook Like button and integrating it into your layout. The problem with this, is that when the user clicks the Like button in the WebView, it will want to open a Javascript window for the user to login to Facebook, but this dialog will almost definitely not fit in the tiny WebView.

Are there any definitive approaches to adding a FaceBook Like button in an Android App?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心作怪 2024-12-15 17:29:43

嗯,我一周前就试过了。有一个“/like”图形方法,它会返回错误,因为不可能喜欢 SDK 中的某些内容。所以你别无选择,只能启动网站。

Well, I tried that a week ago. There is a "/like" graph method, which returns an error since it is not possible to like something from the SDK. So you have no choice but launching the website.

明天过后 2024-12-15 17:29:43

“赞”按钮可用于赞 Facebook 页面或任何开放图谱对象,并且可以通过 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);
    ...

< img src="https://i.sstatic.net/y9KMs.png" alt="在此处输入图像描述">

The Like button can be used to like a Facebook Page or any Open Graph object and can be referenced by URL or ID. Here's what the code looks like.
documentation android facebook sdk
In your Activity or Fragment's onCreate method, use either the UiLifecycleHelper or call 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);
    ...

Then set the object ID for the Like button (this can be a URL or a Facebook ID):

LikeView likeView = (LikeView) findViewById(R.id.like_view);
likeView.setObjectId("http://shareitexampleapp.parseapp.com/photo1/");

Lastly, call the UiLifecycleHelper again in your onActivityResult method

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);
    ...

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文