简体   繁体   English

使用Webview的Android和Facebook“喜欢”按钮-需要登录

[英]Android and Facebook “like” button using webview - login required

I've added a webview to my Android app so the users can like a specific Facebook page. 我已将Webview添加到我的Android应用中,以便用户可以喜欢特定的Facebook页面。 I've done this using a webview as I've read on here and elsewhere that the Graph API doesn't allow users to like a specific Facebook page. 我已经在这里和其他地方阅读过,使用Web视图完成了此操作,因为Graph API不允许用户喜欢特定的Facebook页面。

However, the webview requires the user to login to Facebook the first time that they open the webview, even if they're already logged into the Facebook app (if installed) or touch.facebook.com in the devices browser. 但是,Web视图要求用户在首次打开Web视图时首次登录Facebook,即使他们已经登录到设备浏览器中的Facebook应用(如果已安装)或touch.facebook.com。

Is there any way around having to login? 有什么办法可以不必登录吗? Can I import any Facebook cookie(s) from the browser into my app in any way, for example? 例如,我可以通过任何方式将任何Facebook cookie从浏览器导入我的应用程序吗?

If I added the Graph API to my app and saved the app's key hash at Facebook, would the user still need to log in once the webview was opened? 如果我将Graph API添加到我的应用程序中并在Facebook上保存了该应用程序的密钥哈希,那么打开Webview后用户是否仍需要登录?

Thanks 谢谢

One approach would be to get an instance of the WebView cookie manager and copy its cookies into your HTTP client cookie store, so that the HTTP client uses the cookies set by the login when subsequently talking to Facebook. 一种方法是获取WebView cookie管理器的实例,并将其cookie复制到HTTP客户端cookie存储中,以便HTTP客户端在随后与Facebook交谈时使用登录名设置的cookie。 Something like this... 像这样

CookieManager cookieManager = CookieManager.getInstance();
String cookieString = cookieManager.getCookie("m.facebook.com");
CookieStore mCookieStore = new BasicCookieStore();
mCookieStore.setCookies(cookieString, ".facebook.com", "//");
mCookieStore.sync();

Note that getCookie only gets the cookie's name=value portion, so you will have to add in the domain name and path for the cookie to work in the HTTP client. 请注意,getCookie仅获取cookie的name = value部分,因此您必须添加域名和路径,cookie才能在HTTP客户端中工作。

Another approach would be to use the Single Sign On (SSO) option on the Facebook SDK authorize function, which will not require a user login if the Facebook app is present and logged in. 另一种方法是使用Facebook SDK授权功能上的“单一登录(SSO)”选项,如果存在并登录了Facebook应用,则不需要用户登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM