【问题标题】:News.Read Facebook Opengraph新闻。阅读 Facebook Opengraph
【发布时间】:2012-06-04 20:18:24
【问题描述】:

我在这里遇到了一些麻烦,你知道 Yahoo!消息?我想创建一个这样的小部件(当您阅读一篇文章时,它会发布在您的 Facebook 上)。

我刚刚创建了 Facebook 应用程序和 Open Graph,但我不知道如何将其插入我的网站,我正在使用 Wordpress,我在 Google 上搜索但我仍然不明白,希望你可以帮帮我。


我还是不明白,我刚刚创建了应用程序和opengraph,还在我的标题和函数上插入了opengraph标签,但是当我尝试打开帖子页面时,我得到“发生错误”怎么办?你能帮帮我吗?

【问题讨论】:

    标签: facebook wordpress facebook-opengraph


    【解决方案1】:

    您需要通过阅读文档了解这些概念的工作原理

    1. 用户在应用中执行操作,例如阅读文章
    2. 应用调用到 Graph API 端点 /me/action:object=Object_URL 的 HTTP POST
    3. Facebook 将抓取对象网页(您的 WordPress 页面),读取其元标记并通过操作将对象连接到用户。

    你的动作是 news.reads,所以你会调用如下

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

    为了完成这项工作,您需要在应用设置中设置内置操作类型readhttps://developers.facebook.com/apps/YOUR_APP_ID/opengraph

    那么你必须有article类型的对象集。

    然后您必须在您的 WordPress 博客上设置一个对象 url,这些是通过插入元标记来完成的

    <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 文件中。然后您必须根据您的主题设置插入函数和 if 语句,例如

    帖子的网址

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

    一个帖子标题

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

    然后你需要对这个 url 进行 lint 以确保你已经正确设置,你可以通过

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

    一旦您确定元标记设置正确,您需要测试前面提到的操作

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

    如果一切都设置好了,这应该返回操作的 id。

    那么你必须使用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 文件中或直接在 single.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>
    

    【讨论】:

    • 此时我必须在哪里写?在您的 Wordpress 博客中发布 graph.facebook.com/me/news.reads?article=[article 对象 URL] 我现在不明白
    • @WawanDenFrastøtende 表示 HTTP POST。您可以在 cURL 中完成测试或使用 JS SDK,就像我在上面所做的那样^^^ FB.api( '/me/news.reads',
    • 我还是不明白,我刚刚创建了应用程序和opengraph,还在我的标题和功能上插入了opengraph标签,但是当我尝试打开帖子页面时,我得到“发生错误”怎么办?你能帮帮我吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 2016-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多