任何避免“不受支持的浏览器......”的解决方法当试图在IOS上使用FB.ui时 [英] Any workaround to avoid "unsupported browser ..." when trying to use FB.ui on chrome on IOS

查看:307
本文介绍了任何避免“不受支持的浏览器......”的解决方法当试图在IOS上使用FB.ui时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone上使用FB.ui API尝试打开共享对话框时,出现不受支持的浏览器:Chrome for Chrome不支持此功能,请使用Safari并重试。



我想这个问题是相关的 Facebook OAuth不支持在iOS中使用Chrome浏览器,但我有兴趣自行分享和不进行身份验证(即我不在乎用户是否会登录,我也不知道)。


<我知道这是一个古老的问题,但如果其他人面临这样的问题,(我的意思是一些谷歌搜索让我在这里出于某种原因)。

facebook共享对话框不需要登录即可共享。



https://developers.facebook.com/docs/sharing/reference/share-dialog



通常您使用js sdk,如下所示:

  FB.ui({
方法:'share',
href:'https://developers.facebook.com/docs/',
},function(response){});

不幸的是,这不适用于iOS上的Chrome,但幸运的是, b(如果你使用php);

$ $ isIosChrome =(strpos($ _ SERVER ['HTTP_USER_AGENT']''CriOS' )!== false)?真假;
if($ isIosChrome == true){
$ iosChromeShareLink ='https://www.facebook.com/dialog/share
?app_id ='。$ settings ['facebook'] ['appId']。'
& display = popup
& href ='。urlencode($ THE_SITE_U_WANT_TO_SHARE)。'
& redirect_uri ='。urlencode($ settings ['facebook '] [' 的redirectUrl']);





$ b

因此,基本上,您需要检测用户是否在iOs上使用Chrome,然后用FB分享器链接替换FB.ui功能的触发器元件。因为你不想一直使用共享者,所以只有当js sdk不工作时。



因为互联网上的每个站点都被视为脸书的OG对象您只需确保您的网站包含正确的OG标签。



但是,如果您的Facebook应用(或网站)需要登录才能用于其他目的,并且您面对不受支持浏览器的消息,你可以登录你的用户通过PHP的重定向登录(这要求你使用PHP SDK)。



 使用Facebook \FacebookSession; 
使用Facebook \ FacebookRedirectLoginHelper;
使用Facebook的FacebookRequest;
使用Facebook \GraphUser;
使用Facebook\FacebookRequestException;
$ b $ **
*修正了IOS上的错误BUG
*
*
* /
$ isIosChrome =(strpos($ _ SERVER [ 'HTTP_USER_AGENT'],'CriOS')!== false)?真假;
if($ isIosChrome == true){

FacebookSession :: setDefaultApplication(
$ settings ['facebook'] ['appId'],
$ settings [ 'facebook'] ['secret']
);
$ helper = new FacebookRedirectLoginHelper($ settings ['facebook'] ['redirectUrl']);
$ session = $ helper-> getSessionFromRedirect();
if($ session){
// var_dump($ session);
$ user_profile =(new FacebookRequest(
$ session,'GET','/ me'
)) - > execute() - > getGraphObject(GraphUser :: className()) ;
$ uid = $ user_profile-> getID;
echo $ uid;
}
else {
$ loginUrl = $ helper-> getLoginUrl();
header(location:。$ loginUrl);
出口;
}
}


I am getting an "unsupported browser: chrome for ios doesn't support this feature. Please use safari and try again" when trying to open a share dialog by using the FB.ui API on an iphone.

I guess this question is related Facebook OAuth "Unsupported" in Chrome on iOS, but I am interested in sharing and not authentication by itself (ie I don't care if a user will login and I will not know about it).

解决方案

I know this is an old question but if anyone else faces this kind of problem, (I mean some googling got me here for a reason).

The facebook share dialog doesn't need a login to share.

https://developers.facebook.com/docs/sharing/reference/share-dialog

Usually you use the js sdk, like so:

FB.ui({
  method: 'share',
  href: 'https://developers.facebook.com/docs/',
}, function(response){});

Unfortunally this will not work in Chrome on iOs, but luckily there is a workaround for this (If you are using php);

$isIosChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'CriOS') !== false) ? true : false;
if ($isIosChrome == true) {
    $iosChromeShareLink = 'https://www.facebook.com/dialog/share
        ?app_id='.$settings['facebook']['appId'].'
        &display=popup
        &href='.urlencode($THE_SITE_U_WANT_TO_SHARE).'
        &redirect_uri='.urlencode($settings['facebook']['redirectUrl']);
}

So basically, you need to detect if the user uses Chrome on iOs and then replace your trigger element for the the FB.ui function with the "FB sharer"-link. Because you dont want to use the sharer all the time, only when the js sdk is not working.

And because every site on internet are treated as OG-objects by facebook you just need to make sure your site contains the correct OG-tags.

But if your facebook app(or site) require login for other purposes and you face the "unsupported browser" message by chrome, you could login your users thru the php redirect login (This require you to use the php sdk).

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;

/**
*FIXES CHROME ON IOS BUG
*
*
*/
$isIosChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'CriOS') !== false) ? true : false;
if ($isIosChrome == true) {

    FacebookSession::setDefaultApplication(
        $settings['facebook']['appId'],
        $settings['facebook']['secret']
        );
    $helper = new FacebookRedirectLoginHelper($settings['facebook']['redirectUrl']);
      $session = $helper->getSessionFromRedirect();
    if ($session) {
      //var_dump($session);
        $user_profile = (new FacebookRequest(
          $session, 'GET', '/me'
        ))->execute()->getGraphObject(GraphUser::className());
        $uid=$user_profile->getID;
        echo $uid;
    }
    else{
      $loginUrl = $helper->getLoginUrl();
      header("location:".$loginUrl);
      exit;
    }
}

这篇关于任何避免“不受支持的浏览器......”的解决方法当试图在IOS上使用FB.ui时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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