简体   繁体   中英

Ionic Cordova AngularJs : Why Facebook share works in Ionic serve (browser) but not pop-up display in Android Device?

With the following code, it works with "ionic serve" (browser), when I click on the "Facebook share button", I obtain a "Facebook window pop-up" and I can share datas without any problems.

When I test on my Android Device, I click on the "Facebook Share button", nothing's happen ! And I obtain no error in the console with "chrome://inspect/#devices"

  1. My "Facebook pop-up" is it blocked on device ?
  2. Why is not displayed on device ?
  3. Any ideas ?

In my Controller

window.fbAsyncInit = function() {
  FB.init({
    appId  : 'xxxMyIdxxx',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true  // parse XFBML
  });
};

(function() {
  var e = document.createElement('script');
  //e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
  e.src="https://connect.facebook.net/en_US/all.js";
  e.async = true;
  document.getElementById('share_button').appendChild(e);
}());

$scope.shareFacebook = function(){

  var titleShareFb = "myTitle1";
  var imgShareFb = "http://www.example.com/img/1.jpg";

  //e.preventDefault();
  FB.ui({
    method: 'feed',
    name: titleShareFb,
    link: 'http://www.example.com',
    picture: imgShareFb,

    caption: 'myCaption1',
    description: 'myDescription1',
    message: ''
  });
}; //end of $scope.shareFacebook = function(){

In my View

<div id="cssShareFacebook">
    <img ng-click="shareFacebook()" id="share_button" src="http://www.example.fr/img/facebookShare.png">
</div>

Thank you

here you are the best solution that I can found :

I used this source (Look carefully at what you can do and what you can not do) https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/blob/master/README.md

In Ionic Front, I call an url

$scope.urlFacebook = function(){
  var urlFb = "http://www.troubadourstory.fr/App/fb_share/" + $scope.point._id;
  window.plugins.socialsharing.share(null, null, null, urlFb);   
};

in back I use Html meta like this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" class="">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta http-equiv="imagetoolbar" content="no">
    <title>J'ai visité "<%= dataPoi.Poi.title %>" avec l'application mobile Troubadour Story !</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache,must-revalidate">
    <meta http-equiv="expires" content="0">
    <meta property="og:image" content="<%= dataPoi.Poi.picture %>" height="150px" width="150px">
    <meta name="keywords" content="<%= dataPoi.Poi.title %>">
    <meta name="description" content='Présenté par "<%= dataPoi.Poi.user.username %>" : <%= dataPoi.Poi.content %>'>
  </head>

you can test you URL from HTML meta with this link https://developers.facebook.com/tools/debug

Hope, this, can help ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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