简体   繁体   English

Facebook 页面访问令牌

[英]Facebook Page Access Token

i want to bind the rating information from Facebook Page into my website.我想将 Facebook 页面的评级信息绑定到我的网站。

First i get the Information from the Graph API Explorer, and that works well.首先,我从 Graph API Explorer 中获取信息,效果很好。

Know i have tried to programming this with javascript and i have problems with the page access token.知道我曾尝试使用 javascript 对此进行编程,但我在页面访问令牌方面遇到了问题。

      FB.api('/{page-id}/ratings', function(response) {
          console.log(response);

      });

The Stacktrace:堆栈跟踪:

在此处输入图像描述

How can i include/programming the Page Access Token into the function?我如何将页面访问令牌包含/编程到 function 中?

You need to use a Page Token, and you need to use it on your server - do not use the JavaScript SDK for this.您需要使用页面令牌,并且需要在您的服务器上使用它 - 请勿为此使用 JavaScript SDK。 Using a Page Token on the client would be a bad idea, you should never expose a Token on the client - especially not an Extended Page Token , which is what you would want to use in that case).在客户端使用 Page Token 将是一个坏主意,您永远不应该在客户端上公开 Token - 尤其不是Extended Page Token ,这是您在这种情况下想要使用的)。

How to generate an Extended Page token is explained in the docs, here are some links:文档中解释了如何生成扩展页面令牌,这里有一些链接:

Here´sa general tutorial:这是一个通用教程:

  • Get a User Token with the manage_pages permission获取具有manage_pages权限的用户令牌
  • Extend the User Token扩展用户令牌
  • Get an Extended Page Token with /page-id?fields=access_token使用/page-id?fields=access_token获取扩展页面令牌

You should also consider caching the results in your database instead of reading from the Facebook API whenever a new user hits your page.您还应该考虑将结果缓存在您的数据库中,而不是在新用户访问您的页面时从 Facebook API 读取。

To access page specific data, first you need to obtain a page access token for the specific page and then call the api along with that token.要访问页面特定数据,首先您需要获取特定页面的页面访问令牌,然后调用 api 以及该令牌。

//Load FB js SDK here

function getpages() {
    FB.api('/me/accounts', function(response) {
        console.log('page details');
        console.log(response);
        $.each(response.data,function(index, item){
            $("#fbpgs").append("<div class='row'>"+item.name+"<button onclick='getads("+item.id+",\""+item.access_token+"\")' >Show details</button></div>");
        });
    });
}

function get_page_data(pid,token) {
    $("#lead_forms").html("");
    $(".dv").removeClass("seldiv");
    $(dv).parent().parent().addClass("seldiv");
    FB.api("/"+pid+"/leadgen_forms",{access_token : token}, function(response) {
        console.log('page details');
        console.log(response);
    });
}

<button onclick='getpages()'>load pages</a>
<div class='fbpgs'></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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