Facebook的类似按钮的WebView与SDK [英] Facebook like button in WebView with SDK

查看:150
本文介绍了Facebook的类似按钮的WebView与SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现Facebook的Like按钮而不是使用的WebView的Andr​​oid Facebook的SDK的一部分。这个想法是很简单的。我用SDK登录到使用SSO因此用户并不需要的,如果已经登录的用户在Android的应用程序FB再次输入登录/密码的用户帐号。然后我想用的WebView插入标准的Like按钮。
我已经有用户身份验证令牌,权限上墙等发送状态的问题是如何分辨的WebView用户已经登录。我试图用的WebView(启用JS)这个URL(webview.loadURL())通过FB生成:

<$p$p><$c$c>http://www.facebook.com/plugins/like.php?href=myurl&send=false&layout=button_count&width=450&show_faces=true&action=like&colorscheme=light&font&height=21&appId=myId"             +与&amp;标记=+ mFacebook.getAccessToken()+&安培;期满=+ mFacebook.getAccessExpires(); //(或替代的auth_token)&LT; BR&GT;

显然,这是错误的/或者没有足够多以这种方式发送autorization因为后点击Like按钮用户重定向到网络浏览器登录页面。
所以,问题是如何编辑此URL或如何设置cookies(怎么设置网址CookieManager并曲奇)的web视图登录用户。照片 感谢您的帮助!

解决方案

我不太肯定FB应用程序的访问令牌是有效使用Web API,但是让我们尝试一些东西。

首先,确保你实际使用的cookies为您的WebView例如:

  CookieManager.getInstance()setAcceptCookies(真)。
 

我不知道Facebook的重定向页面是否会尝试设置Cookie,那么试试这个,看看它的伎俩:

  webview.setWebViewClient(新WebViewClient(){
  @覆盖
  公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL)
  {
    view.loadUrl(URL);
    返回true;
  }
});
 

这将迫使你的WebView内自己打开的链接,所以饼干 - 如果有的话 - 也不会丢失的情况下,像网页发出重定向

如果问题仍然存在,你也可以尝试通过执行此手动设置cookie,然后在你的WebView加载的网址:

  //这只是初始化同步经理,做一次
CookieSyncManager.createInstance(本);

CookieManager.getInstance()。setCookie方法(facebook.com,令牌=
        + mFacebook.getAccessToken()+;域= facebook.com);
CookieSyncManager.getInstance()同步()。
 

I'm trying to implement Facebook Like button which is not part of Android Facebook SDK using WebView. The idea is very simple. I use SDK to log into user account using SSO so user don't need to type login/password again if user is already logged in android FB app. Then I want to use WebView to insert standard Like Button.
I already have user auth token, permission for sending status on the wall etc. The problem is how to tell WebView that user is already sign-in. I was trying to use WebView (with enabled JS) with this URL (webview.loadURL()) generated by FB:

http://www.facebook.com/plugins/like.php?href=myurl&send=false&layout=button_count&width=450&show_faces=true&action=like&colorscheme=light&font&height=21&appId=myId"
            + "&token=" + mFacebook.getAccessToken()+"&expires="+mFacebook.getAccessExpires(); //(or auth_token instead)<br>

Obviously this is wrong/or is not enought to send autorization in this way because after click on Like button user is redirected to login page in web browser.
So the question is how to edit this URL or how to set cookies (what to set to URL in CookieManager and which cookies) in WebView to sign user in.
Thanks for any help!

解决方案

I'm not quite sure about FB app access token being valid for using the web api, but let's try something.

First, make sure you're actually using cookies for your WebView instance:

CookieManager.getInstance().setAcceptCookies(true);

I'm not sure whether the facebook redirect page will try to set cookies, so try this and see if it does the trick:

webview.setWebViewClient(new WebViewClient() {  
  @Override  
  public boolean shouldOverrideUrlLoading(WebView view, String url)  
  {  
    view.loadUrl(url);  
    return true;
  }  
});

This will force your WebView to open links within itself, so cookies - if any - won't be lost in case the like page issues a redirect.

If problem still persists you can also try setting cookies manually by executing this before you load the url in your WebView:

// This just initializes the sync manager, do it once
CookieSyncManager.createInstance(this);

CookieManager.getInstance().setCookie("facebook.com", "token="
        + mFacebook.getAccessToken() + "; domain=facebook.com");
CookieSyncManager.getInstance().sync();

这篇关于Facebook的类似按钮的WebView与SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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