如果用户喜欢某个页面,如何发布到新闻Feed? [英] How to post to a news feed if a user has liked a page?

查看:339
本文介绍了如果用户喜欢某个页面,如何发布到新闻Feed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我听说,通过Facebook Open Graph API,可以发布如果用户喜欢某个页面,可以使用该用户的新闻稿



我一直尽力跟随该示例,并且创建了一个虚拟页面



As根据我的理解,有必要做以下事情:


  1. 创建必要的Open Graph标签,包括您的Facebook应用程序


  2. 在页面上添加一个相似的按钮

  3. '像'页面

  4. 获取访问令牌发布消息)

      curl -F grant_type = client_credentials -F client_id = MY_APP_ID -F client_secret = MY_APP_SECRET -F redirect_uri = https://graph.facebook.com/oauth/access_token https://graph.facebook.com/oauth / access_token 


  5. 发布到Feed



    -F'message = Hello Likers'-F'id = http://dl.dropbox.com/u/3618086/test.html

    'https://graph.facebook.com/feed


在这一点上,消息应该发送给喜欢该页面的任何人。相反,我收到以下错误:

  {
error:{
message (#100)http:\ / \ / dl.dropbox.com\ / u\ / 3618086\ / / test.html无法解析为有效的用户ID,
type: OAuthException,
code:100
}
}

在这一点上,我很困惑。我已阅读了以下相关问题:





并尝试了他们的建议,但没有任何成功。我错过了哪一步?



我可以提供更多的细节;我只是不想要这个问题太久了。

解决方案

好吧,我想出了我的问题。我在下面列出我的解决方案,以获得别人的利益。



上面列出的步骤确实是正确的,但有一些事情需要进一步解释



发布给喜欢Facebook上的项目的人



步骤1 :创建Facebook应用程序




  • 您需要访问 Facebook Developers 页面,并创建一个新的应用程序

    • 您不应该需要一个命名空间或应用程序的webhosting


  • 填写您的申请资料

    • 主要地,您需要选择 Facebook登入。 站点URL 应与您的站点托管的位置相同。在我的例子中,我正在托管我的保管箱共享文件夹,所以我使用 http://dropbox.com

    • 设置你的应用程序域到您的站点URL的主机名。在我的情况下,这是 dropbox.com ,这将允许Facebook使用 *。dropbox.com 。我也可以特别做到 dl.dropbox.com




步骤2:创建虚拟页面



创建虚拟页面非常重要。我发现我的大部分问题是由初始页面设置错误引起的。如果你创建一个虚拟页面,你可以尝试(或至少创建另一个虚拟页面)直到一切正常。




  • Make确保您的页面正确,特别是打开的图形标签。 正确是什么样子?您可以查看我的虚拟页面,但我已经包含< HEAD> 以下:

      <?xml version =1.0 = UTF-8 >?; 
    <!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Strict // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
    < html lang =enxml:lang =enxmlns =http://www.w3.org/1999/xhtmlxmlns:fb =http://www.facebook.com / 2008 / fbmlxmlns:og =http://ogp.me/ns#>
    < head>
    < title>测试< / title>
    < link href =http://dl.dropbox.com/u/3618086/test2.html =canonical/>
    < meta property =fb:app_idcontent =YOUR_APP_ID>

    < meta property =og:typecontent =product>
    < meta property =og:titlecontent =PAGE TITLE/>
    < meta property =og:descriptioncontent =PAGE DESCRIPTION/>
    < meta property =og:imagecontent =http://www.stanford.edu/group/cardinalballet/Pictures/WebsitePics/portrait-placeholder.jpg>

    < meta property =og:site_namecontent =SITE_NAME/>
    < meta property =og:urlcontent =http://dl.dropbox.com/u/3618086/test2.html>
    < / head>




    • 这个关键的部分是 fb :app_id (应该是您的Facebook应用程序ID),而 og:type 。有多个类型,某些没有发布权限。有关详细信息,请访问 Open Graph API文档。我最初喜欢我的页面,当它是一篇文章,这引起了我的许多问题。

    • 您还可以使用 Open Graph Debugger


  • 类似按钮添加到页面,以及Facebook SDK。




步骤3:像页面



整个过程中最直接的部分。访问您的虚拟页面,然后按 按钮。



步骤4:发送消息



假设您已经正确完成了以前的步骤,最后一点也应该是直截了当的。我在我的例子中使用 curl ,但您应该可以使用任何POST请求获取它。




  • 获取访问令牌。

      curl -F grant_type = client_credentials -F client_id = MY_APP_ID -F client_secret = MY_APP_SECRET -F redirect_uri = https:// graph。 facebook.com/oauth/access_token https://graph.facebook.com/oauth/access_token 


  • 获取产品页面的ID。

      curl -g https://graph.facebook.com/\? id \ = PAGE_URL 


  • 向喜欢您的产品页面的所有人发送消息。 / p>

      curl -F'access_token = ACCESS_TOKEN'-F'message = MESSAGE'-F'id = ID_FROM_PREVIOUS_ACTION'https:// graph 

    $ h



    步骤5:成功!



    在这一点上,希望一切顺利。作为喜欢该页面的用户,请查看他们的新闻资讯。您应该看到一个帖子,其中包含您的页面上的标题,图像和描述。 Hooray。



    ...这就是我如何解决它。希望这对其他人来说是有价值的。如果我错过了任何细节,我会很乐意。


    Recently, I heard that, with the Facebook Open Graph API, it is possible to post to a user's newsfeed if they have liked a page.

    I have been trying my best to follow along with the example, and have created a dummy page.

    As far as I understand it, it is necessary to do the following:

    1. Create the necessary Open Graph tags, including the one for your Facebook app
    2. Add a like button to the page
    3. 'Like' the page
    4. Obtain an access token (to post the message)

      curl -F grant_type=client_credentials -F client_id=MY_APP_ID -F client_secret=MY_APP_SECRET -F redirect_uri=https://graph.facebook.com/oauth/access_token https://graph.facebook.com/oauth/access_token
      

    5. Post to the feed

      curl -F 'access_token=ACCESS_TOKEN_FROM_STEP_4' -F 'message=Hello Likers' -F 'id=http://dl.dropbox.com/u/3618086/test.html' https://graph.facebook.com/feed
      

    It's at this point that the message should be sent to anyone who liked the page. Instead, I get the following error:

    {
        "error": {
            "message": "(#100) http:\/\/dl.dropbox.com\/u\/3618086\/test.html does not resolve to a valid user ID",
            "type": "OAuthException",
            "code":100
        }
    }
    

    It's at this point that I'm confused. I've read through these related questions:

    And have tried their suggestions, but nothing has been successful. What step am I missing?

    I can provide further details; I just didn't want the question to get too long.

    解决方案

    Alright, I figured out my problem. I'm including my solution below for the benefit of others.

    The steps I've listed above are indeed correct, but there are a few things that warrant further explanation to avoid the pitfalls that I fell into.

    Posting to people who have liked an item on Facebook

    Step 1: Create a Facebook App

    • You'll need to visit the Facebook Developers page and create a new application
      • You should not need a namespace, or webhosting for your application
    • Fill out the details for your application
      • Primarily, you'll need to select "Website with Facebook Login". The site URL should be the same as where your site is hosted. In my example, I am hosting in my dropbox shared folder, so I used http://dropbox.com
      • Set your App Domain to the hostname of your site URL. In my case, this is dropbox.com which will allow Facebook to use *.dropbox.com. I also could have done dl.dropbox.com specifically.

    Step 2: Create the dummy page

    It is very important that you create a dummy page. I found that most of my problems were caused by setting up the initial page wrong. If you create a dummy page, you can experiment (or at least create another dummy page) until everything is working.

    • Make sure that your page is correct, especially the open graph tags. What does correct look like? You can check out my dummy page, but I've included the <HEAD> below:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://ogp.me/ns#">
      <head>
          <title>Test</title>
          <link href="http://dl.dropbox.com/u/3618086/test2.html" rel="canonical" />
          <meta property="fb:app_id" content="YOUR_APP_ID">
      
          <meta property="og:type" content="product">
          <meta property="og:title" content="PAGE TITLE" /> 
          <meta property="og:description" content="PAGE DESCRIPTION" /> 
          <meta property="og:image" content="http://www.stanford.edu/group/cardinalballet/Pictures/WebsitePics/portrait-placeholder.jpg">
      
          <meta property="og:site_name" content="SITE_NAME"/>
          <meta property="og:url" content="http://dl.dropbox.com/u/3618086/test2.html">
      </head>
      

      • The critical piece of this are the fb:app_id (which should be your Facebook application id), and og:type. There are multiple types, and certain ones don't have publish permissions. For more information, visit the Open Graph API documentation. I initially liked my page when it was an article, which caused many of the problems that I had.
      • You can also check the page for Open Graph errors using the Open Graph Debugger
    • Add the like button to the page, along with the Facebook SDK.

    Step 3: Like the page

    The most straightforward part of the entire process. Visit your dummy page, and press the Like button.

    Step 4: Send a message

    Assuming that you've done the previous steps correctly, the last bit should also be straightforward. I use curl in my example, but you should be able to get it using any sort of POST request.

    • Obtain an access token.

      curl -F grant_type=client_credentials -F client_id=MY_APP_ID -F client_secret=MY_APP_SECRET -F redirect_uri=https://graph.facebook.com/oauth/access_token https://graph.facebook.com/oauth/access_token
      

    • Obtain the id of your product page.

      curl -g https://graph.facebook.com/\?id\=PAGE_URL
      

    • Post a message to all people who liked your product page.

      curl -F 'access_token=ACCESS_TOKEN' -F 'message=MESSAGE' -F 'id=ID_FROM_PREVIOUS_ACTION' https://graph.facebook.com/feed
      

    Step 5: Success!

    At this point, hopefully everything has gone well. As the user who liked the page, check out their news feed. You should see a post with the title, image, and description that were on your page. Hooray.

    ...And that's how I solved it. Hopefully this will be valuable to other people. I would be glad to elaborate if I have missed any details.

    这篇关于如果用户喜欢某个页面,如何发布到新闻Feed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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