我想在我的Android应用程序中集成一个类似的按钮.我用过代码
likeWebView = (WebView) findViewById( R.id.webView1 );
likeWebView.getSettings().setJavaScriptEnabled(true);
String url = "http://www.facebook.com/plugins/like.php?" +
"href=" + URLEncoder.encode("likeurl" ) + "&" +
"layout=standard&" +
"show_faces=false&" +
"width=500&" +
"action=like&" +
"colorscheme=light&" +
"access_token=" + URLEncoder.encode( "read_stream" );
likeWebView.loadUrl( url );
Run Code Online (Sandbox Code Playgroud)
但登录后显示空白页面.请给我一个添加Like按钮的解决方案.
最后,Facebook和推出像按键为Android
脚步:
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" />
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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);
}
Run Code Online (Sandbox Code Playgroud)
产量

private initLikeButton( String urlToLike ) {
likeWebView = (WebView) findViewById( R.id.likeWebView );
likeWebView.getSettings().setJavaScriptEnabled(true);
String url = "http://www.facebook.com/plugins/like.php?" +
"href=" + URLEncoder.encode( urlToLike ) + "&" +
"layout=standard&" +
"show_faces=false&" +
"width=375&" +
"action=recommend&" +
"colorscheme=light&" +
"access_token=" + URLEncoder.encode( FacebookAdapter.getInstance().getAccessToken() );
likeWebView.loadUrl( url );
Run Code Online (Sandbox Code Playgroud)
在这里,在您的代码中,您必须放置likeurl、 url 这样的内容。
使用http://developers.facebook.com/docs/reference/plugins/like上的 Like 按钮代码生成器提供的 iframe 代码。但由于 iframe 基本上和 WebView 是一样的,所以在 iframe 中加载代码,然后在 WebView 中加载 iframe 似乎是多余的。因此,我只是使用下面的代码将 iframe 中的代码直接加载到 WebView 中。但无论哪种方式都会发生同样的事情。
顺便说一下,开发 iPhone 应用程序时也存在同样的问题。我们不希望用户每次运行我们的应用程序时都必须登录 Facebook。但不幸的是,如果用户自上次通过我们的应用程序登录 Facebook 以来已经在另一台计算机上登录了 Facebook,他们将不得不再次登录。
在android平台上,我认为更好的解决方案可能是有一个facebook应用程序,您可以向它发送一个意图,该应用程序负责保持用户登录并返回用于渲染like按钮的html。
查看更多: https: //github.com/facebook/facebook-android-sdk/issues/17
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
将 facebook 与 android 和 iphone 中的点赞按钮集成
| 归档时间: |
|
| 查看次数: |
6967 次 |
| 最近记录: |