Android 应用程序中的 Facebook Like 按钮

发布于 2024-12-10 12:00:35 字数 649 浏览 0 评论 0原文

我想在我的 Android 应用程序中显示类似按钮。下面是我用来在 Android 应用程序中显示 Like 按钮的代码。

String url = "http://www.facebook.com/plugins/like.php?layout=standard&show_faces=true&width=80&height=50&action=like&colorscheme=light&href=http://beta.demo.dy/web/service/304.htm"
webview = (WebView) findViewById(R.id.webView1);
webview.loadUrl(url);
webview.setWebViewClient(new LikeWebviewClient());

public class LikeWebviewClient  extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

但是当我运行这个应用程序时,它显示一个白色区域。如何解决这个问题?

I want to display like button in my android application. Below is the code I use to display a Like button in my android application.

String url = "http://www.facebook.com/plugins/like.php?layout=standard&show_faces=true&width=80&height=50&action=like&colorscheme=light&href=http://beta.demo.dy/web/service/304.htm"
webview = (WebView) findViewById(R.id.webView1);
webview.loadUrl(url);
webview.setWebViewClient(new LikeWebviewClient());

public class LikeWebviewClient  extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

But when I run this application it displays a white area. How to resolve this?

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

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

发布评论

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

评论(6

孤独患者 2024-12-17 12:00:35

like 选项可以在本机平台语言(Android、iOS)以及浏览器(curl、PHP、JavaScript)上轻松实现,如下所示。
转到developer.facebook 应用程序部分,在开发人员应用程序配置的开放图谱部分中,添加内置的“点赞”操作,在添加新的开放图谱操作时,该操作应出现在下拉列表中。请参阅此处了解最新更新。

完成后,选择“获取代码”选项来检索示例代码,如下所示(适用于 Android 平台)。您可以选择您所选择的平台。请注意,app_specific_unique_identifier 对于应用程序来说是唯一的,出于安全原因我已将其删除,您必须为您的应用程序使用该标识符。

我已经能够成功测试点赞流程。希望这有帮助。

Bundle params = new Bundle();
params.putString("object", "http://samples.ogp.me/<app_specific_unique_identifier>");

Request request = new Request(
    Session.getActiveSession(),
    "me/og.likes",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response

The like option can be implemented easily on Native platform languages(Android, iOS) as well as browsers (curl, PHP, JavaScript) as follows.
Go to developer.facebook app section and within the Open Graph section of the Developer App configuration, add the built-in Like action, which should appear in the drop-down when adding a new Open Graph action. Refer here for latest updates.

Once done, Select "Get Code" option to retrieve sample code as depicted below for Android platform. You can choose platform of your choice. Note that app_specific_unique_identifier is uniquee for apps, i have removed it for security reasons and you have to use the one for your app.

I have been able to test the Like flow successfully. Hope this helps.

Bundle params = new Bundle();
params.putString("object", "http://samples.ogp.me/<app_specific_unique_identifier>");

Request request = new Request(
    Session.getActiveSession(),
    "me/og.likes",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response
过期以后 2024-12-17 12:00:35

Facebook SDK 尚未为本机移动应用提供like 按钮功能(截至 2011 年 10 月 17 日)。它可在移动网络应用程序中使用。
欲了解更多信息,您可以查看这些链接:
移动 - Facebook 开发者
点赞按钮 - Facebook 开发者

Facebook SDK hasn't provided like button feature for native mobile apps( As of Oct 17 2011). It is available in Mobile Web apps.
For more info you can check out these link:
Mobile - Facebook Developers
Like Button - Facebook Developers

王权女流氓 2024-12-17 12:00:35

最后 Facebook 推出了适用于 Android 的 Like 按钮

步骤:

1 - 添加 Facebook 库到项目

2 - 在 Facebook 上创建应用
3 - 更新清单

**In the Application tab add meta-data**

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

4 - 在布局中添加 LikeView

//activitymain.xml
<com.facebook.widget.LikeView
            android:id="@+id/like_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            >
        </com.facebook.widget.LikeView>

5 - ActivityMain.java

//set facebook page or link to this like button
LikeView likeView;
UiLifecycleHelper uiHelper;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activitymain);
    uiHelper = new UiLifecycleHelper(this, null);
    likeView = (LikeView) findViewById(R.id.like_view);
    likeView.setObjectId("https://www.facebook.com/<page_username>");//it can be any link

    likeView.setLikeViewStyle(LikeView.Style.STANDARD);
    likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
    likeView.setHorizontalAlignment(LikeView.HorizontalAlignment.LEFT);

}

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

    uiHelper.onActivityResult(requestCode, resultCode, data, null);

}

输出
在此处输入图像描述

Finally Facebook and Launched Like Button for Android

Steps:

1 - Add Facebook Library to Project

2 - Create App on Facebook
3 - Update Manifest

**In the Application tab add meta-data**

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

4 - Add LikeView in Layout

//activitymain.xml
<com.facebook.widget.LikeView
            android:id="@+id/like_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            >
        </com.facebook.widget.LikeView>

5 - ActivityMain.java

//set facebook page or link to this like button
LikeView likeView;
UiLifecycleHelper uiHelper;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activitymain);
    uiHelper = new UiLifecycleHelper(this, null);
    likeView = (LikeView) findViewById(R.id.like_view);
    likeView.setObjectId("https://www.facebook.com/<page_username>");//it can be any link

    likeView.setLikeViewStyle(LikeView.Style.STANDARD);
    likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
    likeView.setHorizontalAlignment(LikeView.HorizontalAlignment.LEFT);

}

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

    uiHelper.onActivityResult(requestCode, resultCode, data, null);

}

Output
enter image description here

黑凤梨 2024-12-17 12:00:35

您可以使用 Facebook 开发者帐户的特殊权限在 Android 应用程序中使用 Facebook Like 按钮 https://developers.facebook.com
在此处添加您的应用程序并提交应用程序特殊权限。
转到应用程序审核并提交项目以供批准。
单击开始提交,然后选择喜欢本机按钮并提交他们想要的所有详细信息,例如为什么您想要获得喜欢的权限,您的应用程序将如何使用此权限等一切。
如果 Facebook 批准您的请求,那么您可以在应用程序内使用 facebook like 按钮。在此处输入代码

      <com.facebook.share.widget.LikeView
         android:id="@+id/facebooklike"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
        </com.facebook.share.widget.LikeView>

之后您需要执行一些 java 代码。

likeView = (LikeView) findViewById(R.id.facebooklike);
    likeView.setLikeViewStyle(LikeView.Style.STANDARD);            
   likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
    likeView.setHorizontalAlignment(LikeView.HorizontalAlignment.CENTER);
    likeView.setObjectIdAndType("url of like page", LikeView.ObjectType.PAGE);

当您单击“喜欢”按钮时,“喜欢”功能会自动调用。

现在您需要从用户喜欢该页面或不同于该页面的类似页面获取响应。

enter code here

公共类 FbLikes 扩展 AppCompatActivity {

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {
        if (resultCode == RESULT_OK) {
            // verify we're returning from like action
                // get action results
                bundle = data.getExtras().getBundle("com.facebook.platform.protocol.RESULT_ARGS");
                if (bundle != null) {
                    like = bundle.getBoolean("object_is_liked");// liked/unliked
                    bundle.getInt("didComplete");
                    bundle.getInt("like_count"); // object like count
                    bundle.getString("like_count_string");
                    bundle.getString("social_sentence");
                    bundle.getString("completionGesture"); // liked/cancel/unliked
                    Log.e(TAG, bundle.getString("social_sentence") + "");
                    Log.e(TAG, "likeornot" + bundle.getBoolean("object_is_liked") + "");
                    Log.e(TAG, "lcomplete" + bundle.getString("completionGesture") + "");
                    Log.e(TAG, "count" + bundle.getInt("like_count") + "");
                    Log.e(TAG, "countstr" + bundle.getString("like_count_string") + "");
                    Log.e(TAG, "did" + bundle.getInt("didComplete") + "");
                }
        }
    } catch (Exception e) {

    }
}

}
此代码将从类似功能中返回您想要的所有内容。

You can use facebook like button in android app using special permission from facebook developer account https://developers.facebook.com.
Add your app here and submit app special permission.
Go to app review and submit items for approval.
click on start submission and after that select LIKE native button and submit all details they want like why you want get like permission , how your app will use this permission everything.
If Facebook will approve your request then you can use facebook like button inside app.enter code here

      <com.facebook.share.widget.LikeView
         android:id="@+id/facebooklike"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
        </com.facebook.share.widget.LikeView>

After this you need to do some java code.

likeView = (LikeView) findViewById(R.id.facebooklike);
    likeView.setLikeViewStyle(LikeView.Style.STANDARD);            
   likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
    likeView.setHorizontalAlignment(LikeView.HorizontalAlignment.CENTER);
    likeView.setObjectIdAndType("url of like page", LikeView.ObjectType.PAGE);

like functionality automatically call when you click on like button.

now you need to get response from like page that user like that page of unlike that page.

enter code here

public class FbLikes extends AppCompatActivity {

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {
        if (resultCode == RESULT_OK) {
            // verify we're returning from like action
                // get action results
                bundle = data.getExtras().getBundle("com.facebook.platform.protocol.RESULT_ARGS");
                if (bundle != null) {
                    like = bundle.getBoolean("object_is_liked");// liked/unliked
                    bundle.getInt("didComplete");
                    bundle.getInt("like_count"); // object like count
                    bundle.getString("like_count_string");
                    bundle.getString("social_sentence");
                    bundle.getString("completionGesture"); // liked/cancel/unliked
                    Log.e(TAG, bundle.getString("social_sentence") + "");
                    Log.e(TAG, "likeornot" + bundle.getBoolean("object_is_liked") + "");
                    Log.e(TAG, "lcomplete" + bundle.getString("completionGesture") + "");
                    Log.e(TAG, "count" + bundle.getInt("like_count") + "");
                    Log.e(TAG, "countstr" + bundle.getString("like_count_string") + "");
                    Log.e(TAG, "did" + bundle.getInt("didComplete") + "");
                }
        }
    } catch (Exception e) {

    }
}

}
this code will return everything you want from like functionality.

绝對不後悔。 2024-12-17 12:00:35

试试这个我做了一些修改

String url = "http://www.facebook.com/plugins/like.php?layout=standard&show_faces=true&width=80&height=50&action=like&colorscheme=light&href=http://beta.demo.dy/web/service/304.htm";
                 //   webview = (WebView) findViewById(R.id.webview);
                    webView.loadUrl(url);
                     webView.setWebViewClient(new WebViewClient());
                 class LikeWebviewClient  extends WebViewClient
                    {
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            view.loadUrl(url);
                            return true;
                        }
                    }

Try this one i made some modification

String url = "http://www.facebook.com/plugins/like.php?layout=standard&show_faces=true&width=80&height=50&action=like&colorscheme=light&href=http://beta.demo.dy/web/service/304.htm";
                 //   webview = (WebView) findViewById(R.id.webview);
                    webView.loadUrl(url);
                     webView.setWebViewClient(new WebViewClient());
                 class LikeWebviewClient  extends WebViewClient
                    {
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            view.loadUrl(url);
                            return true;
                        }
                    }
御弟哥哥 2024-12-17 12:00:35

Facebook最近在facebook sdk 3.21.1中提供了likebutton的功能。您可以通过这些链接下载实现likebutton的sdk和教程。

下载SDK:
http://developers.facebook.com/docs/android

教程
http://developers.facebook.com/docs/android/like-button

我希望它可以解决您的问题。

Facebook has recently provided the feature of likebutton in facebook sdk 3.21.1. You can go through these links to download sdk and tutorial for implementation of likebutton.

Download SDK:
http://developers.facebook.com/docs/android

Tutorial
http://developers.facebook.com/docs/android/like-button

I hope it may solve your problem.

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