Facebook共享错误:“网站”类型的URL处的对象无效,因为未提供“string”类型的必需属性“og:title”

时间:2014-07-12 23:31:19

标签: javascript facebook ruby-on-rails-3 facebook-graph-api

出于某种原因,每次我尝试分享自定义故事时,只会在第一次尝试分享时出现以下错误:

Facebook分享错误:网址类型'网站'是无效的,因为必需的属性' og:title'类型'字符串'没有提供。

然而,当我检查我的元标记时,标记显然就在那里。

<meta property="og:title" content="sdfsdsafsd">

每当我第二次分享时,它都能完美运行。这是我的代码

$( document ).ready(function() {

  // You probably don't want to use globals, but this is just example code
  var fbAppId = '***';

  /*
   * This is boilerplate code that is used to initialize
   * the Facebook JS SDK.  You would normally set your
   * App ID in this code.
   */

  // Additional JS functions here
  window.fbAsyncInit = function() {
    FB.init({
      appId      : fbAppId, // App ID
      status     : true,    // check login status
      cookie     : true,    // enable cookies to allow the
                            // server to access the session
      xfbml      : true,     // parse page for xfbml or html5
                            // social plugins like login button below
      version        : 'v2.0',  // Specify an API version
    });

    // Put additional init code here
  };

  // Load the SDK Asynchronously
  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

  /*
   * This function makes a call to the og.likes API.  The
   * object argument is the object you like.  Other types
   * of APIs may take other arguments. (i.e. the book.reads
   * API takes a book= argument.)
   *
   * Because it's a sample, it also sets the privacy
   * parameter so that it will create a story that only you
   * can see.  Remove the privacy parameter and the story
   * will be visible to whatever the default privacy was when
   * you added the app.
   *
   * Also note that you can view any story with the id, as
   * demonstrated with the code below.
   *
   * APIs used in postLike():
   * Call the Graph API from JS:
   *   https://developers.facebook.com/docs/reference/javascript/FB.api
   * The Open Graph og.likes API:
   *   https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes
   * Privacy argument:
   *   https://developers.facebook.com/docs/reference/api/privacy-parameter
   */

  function shareGiftRequest() {
    objectToLike = window.location.href;
    FB.api(
       'https://graph.facebook.com/me/easy-gift:post',
       'post',
       { gift_request: objectToLike,
         privacy: {'value': 'SELF'} },
       function(response) {
         if (!response) {
           alert('Error occurred.');
         } else if (response.error) {
             alert('Facebook share error: ' + response.error.message);
         } else {
            alert(objectToLike);
         }
       }
    );
  }

    $('#facebook_share').click(function(e) {
        e.preventDefault();
        shareGiftRequest();
    });

});

0 个答案:

没有答案