在Android应用Facebook的Like按钮? [英] Facebook Like Button in Android app?

查看:670
本文介绍了在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?

看着 Facebook的Andr​​oid SDK中,对于如何在分享的东西例子来支持你墙上,张贴图片到你的墙,登录,注销,等等...但它似乎没有要增加一个简单的Like按钮什么...我期待能够在Like按钮添加到我的应用程序(通过ImageView的或者一个样式按钮),一旦点击Facebook的将装载授权登录对话框,然后征求您的同意喜欢的应用程序。

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?

有人建议做一个微小的WebView,它是Facebook的HTML Like按钮的大小,并将其整合到您的布局。这里的问题是,当用户点击的WebView的Like按钮,就会想打开一个Javascript窗口,用户登录到Facebook上,但该对话框将几乎可以肯定不适合在微小的WebView。

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.

是否有任何明确的办法,在Android应用程序添加Facebook的Like按钮?

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

推荐答案

该Like按钮可以用于像一个Facebook页面或任何的Open Graph对象,并可以通过URL或ID引用。这里的code样子。
文档 Android的SDK的Facebook
在你的活动或片段的onCreate方法,使用UiLifecycleHelper或拨打Settings.sdkInitialize:

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

然后设置对象ID为Like按钮(这可能是一个网址或Facebook的ID):

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/");

最后,在你的onActivityResult方法再次调用UiLifecycleHelper

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

这篇关于在Android应用Facebook的Like按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆