Fb图api权限不起作用 [英] Fb graph api permissions aren't working

查看:101
本文介绍了Fb图api权限不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Facebook登录及其图形API将用户的所有图像列出到我的网站,以下代码只对我是Facebook应用程序的管理员和所有者才能正常工作,对于任何其他人来说,它不起作用他使用Facebook登录登录网站。


代码说明:当用户登录时,调用名为testAPI的函数,该函数获取用户基本信息,然后再调用FB.API允许访问,然后最终获取图片。


权限参数res对任何其他用户都没有任何影响,但它对我来说(管理员)。

代码:

I am using facebook login and its graph api to list all images of user to my website and the following code is working fine only for me that is the administrator and owner of the facebook app, it is not working for anyother person when he logged in the website using facebook login.

Explanation of code: When user logged in, a function named testAPI is called which gets user basic information and then it makes another call to FB.API for permission access and then finally for getting pictures.

The permission parameter "res" gets nothing for anyother user, but its working for me(administrator).
heres the code:

<div id="fb-root"></div>
 <script>
  // Additional JS functions here
  window.fbAsyncInit = function() {
  FB.init({
   appId      : MY_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
   });


   FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
                testAPI();
 } else if (response.status === 'not_authorized') {
       login();
     } else {
       login();
      }
     });

   };


    function login() {
       FB.login(function(response) {
           if (response.authResponse) {
            testAPI();
            } else {
           // cancelled
           }
         },{scope:'user_photos',perms:'user_photos'});
  }
   var id;
   function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
    console.log('Good to see you, ' + response.name + '.');
    console.log(response);
    id=response.id;

var link='/'+ id + '/permissions?access_token=FB_GENERATED_ACCESS_TOKEN';
 FB.api(link,function(res){
 console.log("permissons: ",res);
     link='/'+ id + '/photos?fields=images';
     FB.api(link, function(response) {
      //placing all pictures
      for(var i=0;i<response.data.length;i++)
      {
            var img="<img src="+response.data[i].images[0].source+" class='small' />";
         $("#images").append(img);
    }      
      console.log(response);
       });      

 });

    });}
   (function(d){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/en_US/all.js";
   ref.parentNode.insertBefore(js, ref);
  }(document));
 </script></body>

  <fb:login-button autologoutlink='true'   
  perms='email,user_birthday,status_update,publish_stream'></fb:login-button>
 <div id="images"></div>


推荐答案

我有你的实际问题,

<fb:login-button autologoutlink='true' 
 perms='email,user_birthday,status_update,publish_stream'></fb:login-button>

您在这里错过了user_photos权限。你的javascript函数不是调用,因为fb:login-button自己做所有的东西。您的新代码应该是:

You missing out here , user_photos permission. your javascript function is not calling because fb:login-button do all stuff by self. your new code should be :

<fb:login-button autologoutlink='true' 
     perms='email,user_birthday,status_update,publish_stream,user_photos'></fb:login-button>

这篇关于Fb图api权限不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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