繁体   English   中英

使用Facebook Graph API进行身份验证并从Facebook页面解析JSON评论

[英]Authenticating with Facebook Graph API & Parsing JSON Reviews from a Facebook Page

我在身份验证和解析时遇到了麻烦。

获取Facebook Graph API页面评论

我尝试将应用提交审核并请求manage_page访问,但出现错误:

“无效范围:manage_pages。仅向开发人员显示此消息。您的应用程序用户将忽略这些权限(如果存在)。请在以下位置阅读文档以获取有效权限:developers.facebook.com/docs/facebook-login/permissions”,可能API已弃用

<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
      <title>Ilan's Test</title>
   </head>
   <body>

   <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <div id="results">

                </div>
            </div>
         </div>
   </div>

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
      <script>
         var myurl = "http://graph.facebook.com/v3.3/FinancialSanityNow/ratings";
         var getToken = function(req, res) {
         var facebookToken = req.headers['facebooktoken'];
         //TODO : check the expirationdate of facebooktoken
         if(facebookToken) {
            var path = 'https://graph.facebook.com/v3.3/FinancialSanityNow?access_token=' + facebookToken;
         request(path, function (error, response, body) {
            var facebookUserData = JSON.parse(body);
         if (!error && response && response.statusCode && response.statusCode == 200) {
          if(facebookUserData && facebookUserData.id) {
            var accessToken = jsonWebToken.sign(facebookUserData, jwtSecret, {
                //Set the expiration
                expiresIn: 86400
            });
            res.status(200).send(accessToken);
         } else {
           res.status(403);
           res.send('Access Forbidden');
                             }
         }
         else {
           console.log(facebookUserData.error);
           //console.log(response);
           res.status(500);
           res.send('Access Forbidden');
         }
         });
           res.status(403);
           res.send('Access Forbidden');
         }
         };
         $.ajax({
            url: myurl,
            headers: {
             'access_token':'xxxxxaccesstokenherexxxxx',
         },

            method: 'GET',
            dataType: 'json',

            success: function(data){
                    $.each(data.reviews, function(i, item) {
                        // Store each review object in a variable
                        var reviewdata = item.data.reviews;
                        // Append our result into our page
                        $('#results').append('test:' + reviewdata);
                  });
            }
         });     

      </script>
   </body>
</html>

我只想通过Facebook的pages / ratings api知道是否有可能

https://developers.facebook.com/docs/graph-api/reference/page/ratings/

在使用大多数权限之前,需要对其进行审核。 未经审查,它们将仅对在应用程序中具有角色的用户有效,并且您需要将应用程序保持在开发模式。 如果您将其发布,则未经批准的权限将根本无法使用。

另外,您必须使用相关页面的页面令牌来获取评论,通过使用/me/accounts?fields=access_token端点来获取页面令牌,并且用户令牌必须包含manage_pages权限。

有关令牌的更多信息: https : //developers.facebook.com/docs/facebook-login/access-tokens/

暂无
暂无

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

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