无法使用node.js与facebook的图形API进行交互

时间:2017-01-19 07:09:14

标签: node.js facebook facebook-graph-api

这是我想要点击的网址:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal1" style="background: #CCC; width: 1000px;height 1000px; position: absolute; top: 100px; left: 0px;">

              <ul class="bxslider">
                <li class="">

                    <img src="http://1.bp.blogspot.com/_gTJMEP-c2fo/SLffF6y0iTI/AAAAAAAAEAc/aGZ3z7Gc4ac/s640/Cat+Kiss+4.jpg">
                    <br>
                    <p><a class="modal-close">CLOSE</a></p>
                    
                </li>
                <li class="">

                    <img src="https://s-media-cache-ak0.pinimg.com/736x/62/26/9c/62269c9bb6312f35247579865d895a33.jpg"><br>
                    <p><a class="modal-close">CLOSE</a></p>

                </li>
                <li class="">
                

                    <img src="https://s-media-cache-ak0.pinimg.com/736x/d4/d2/3f/d4d23fa5509136af2a51c69b6af58839.jpg">
                    <br>
                    <p>
                    
                    <a class="modal-close">CLOSE</a></p>

                </li>
              </ul>
        
            </div>

            <a class="sampleclick">BUTTON 1</a>
            
            <a class="sampleclick">BUTTON 2</a>

预期结果:(与Graph API Explorer一样):

https://graph.facebook.com/v2.8/me?fields=friends?access_token=xxxx.

致电获取朋友数量:(node.js)

{
  "friends": {
    "data": [
    ],
    "summary": {
      "total_count": 648
    }
  },
  "id": "xxxx"
}

获取朋友数的方法:(node.js)

fb.getFbData(constants.AccessToken, 'me?fields=friends', function(data){
        res.send(data);
    });

错误:

enter image description here

1 个答案:

答案 0 :(得分:1)

有两件事是错的:

  1. 网址不正确,传递的第二个参数没有'&amp;'在URL。

  2. 当使用https.get和'options'时,如下所示:

    var options = {             主持人:'graph.facebook.com',             港口:443,             路径:apiPath +'?access_token ='+ accessToken,             方法:'GET'         };

  3. 然后,'host'被附加在URL中,因此'path'只需要包含网站上的目录。例如:/v2.8/me?fields=friends