2012-05-30 89 views
1

我在這裏有一些麻煩,你知道雅虎嗎?新聞?我想創建一個像這樣的小部件(當你閱讀一篇發表在你的Facebook上的文章時)。News.Read Facebook Opengraph

我剛剛創建了Facebook應用程序和Open Graph,但我不明白如何將其插入到我的網站,我正在使用Wordpress,並且我在Google上搜索,但我仍然不明白,希望您能夠幫助我。


我還是不明白,我剛剛創建的應用程序,也是opengraph,還插入opengraph標籤上我的頭和功能,但是當我嘗試打開網頁後,我得到「錯誤發生「如何?你可以幫我嗎?

回答

5

您需要了解的閱讀文檔

  1. 用戶採取行動的應用程序,如閱讀文章
  2. 應用程序調用一個HTTP POST到圖形API終點的概念是如何工作的/ me/action:object = Object_URL
  3. Facebook將抓取對象網頁(您的WordPress頁面),讀取其元標記並通過操作將對象連接到用戶。

你的動作是news.reads,所以你會叫如下

POST https://graph.facebook.com/me/news.reads?article=[article object URL in your Wordpress Blog]

爲了這個工作,你需要設置內置動作類型read在應用設置:https://developers.facebook.com/apps/YOUR_APP_ID/opengraph

news.read in app settings

然後,你必須有article類型爲對象設置。

Article Object

然後,你必須建立一個URL對象在你的WordPress博客這些被插入元標記做

<html> 
    <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# 
        article: http://ogp.me/ns/article#"> 
    <meta property="fb:app_id"    content="YOUR_APP_ID"> 
    <meta property="og:type"     content="article"> 
    <meta property="og:url"     content="URL of this object"> 
    <meta property="og:site_name"   content="Name of site hosting article"> 
    <meta property="og:image"    content="URL to an image"> 
    <meta property="og:title"    content="Name of article"> 
    <meta property="og:description"   content="Description of object"> 
    <meta property="article:published_time" content="DateTime"> 
    <meta property="article:modified_time" content="DateTime"> 
    <meta property="article:expiration_time" content="DateTime"> 
    <meta property="article:author"   content="URL to Author object"> 
    <meta property="article:section"   content="Section of article"> 
    <meta property="article:tag"    content="Keyword"> 
    </head> 
<body> 
    <!-- main article body --> 
</body> 
</html> 

所以你會把這些在你的header.php或index.php文件根據您的主題設置。然後,你將不得不插入功能,如果基於你的主題設置語句,如

<meta property="og:url" content="<?php the_permalink() ?>"/> 

單篇文章的標題

<meta property="og:title" content="<?php single_post_title(''); ?>" /> 

然後,你需要皮棉本的網址網址以確保您已正確設置,您可以通過

http://developers.facebook.com/tools/debug 

一旦您是su重新meta標籤設置正確,你需要測試的動作如果一切本應返回動作的ID如前所述

POST https://graph.facebook.com/me/news.reads?article=[article object URL in your Wordpress Blog]

則必須實現使用JS SDK

<div id="fb-root"></div> 
    <script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
     appId  : '[YOUR_APP_ID]', // App ID 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true // parse XFBML 
     }); 
    }; 

    // Load the SDK Asynchronously 
    (function(d){ 
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.src = "//connect.facebook.net/en_US/all.js"; 
     d.getElementsByTagName('head')[0].appendChild(js); 
    }(document)); 
    </script> 

用於身份驗證的邏輯和登錄按鈕插件

<fb:login-button show-faces="true" width="200" max-rows="1" scope="publish_actions"> </fb:login-button>

無論是在functions.php文件或在單直接。 php和index.php頁面

從那裏你必須創建一個函數來調用頁面加載下面的動作

<script type="text/javascript"> 
    function readArticle() 
    { 
     FB.api(
     '/me/news.reads', 
     'post', 
     { article: 'http://yourwordpress.com/site/' }, 
     function(response) { 
      if (!response || response.error) { 
       alert('Error occured'); 
      } else { 
       alert('Article read was successful! Action ID: ' + response.id); 
      } 
     }); 
    } 
    </script> 
+0

在這裏我必須寫? POST https://graph.facebook.com/me/news.reads?article=[article對象URL在你的Wordpress博客] 我不明白在這一點 –

+0

@WawanDenFrastøtende代表一個HTTP POST。你可以在cURL中完成測試或使用JS SDK,就像我上面做的那樣^^^'FB.api( '/ me/news.reads',' – phwd

+0

我還是不明白,我剛剛創建了應用程序並且也opengraph,也插入opengraph標記在我的頭和功能,但是當我嘗試打開帖子頁,我得到「錯誤發生」如何?你能幫我嗎? –