Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
facebook好友列表_Facebook_Fbjs - Fatal编程技术网

facebook好友列表

facebook好友列表,facebook,fbjs,Facebook,Fbjs,如何使用新的facebook api获取好友列表。我用下面的代码得到了朋友名单 $friends=$facebook->api('/uid/friends') 但是,如果我在同一个函数中传递他们的用户ID,我就无法获取朋友列表。你不能,这是他们的私人数据,所以它在他们的控制之下。如果他们想让应用程序访问它,他们会授予权限,它可以代表他们这样做。Facebook好友列表只获取可标记的好友列表 Facebook不会访问完整的个人资料好友列表,它只显示您个人资料中的好友列表总数 pod和plist设置

如何使用新的facebook api获取好友列表。我用下面的代码得到了朋友名单

$friends=$facebook->api('/uid/friends')


但是,如果我在同一个函数中传递他们的用户ID,我就无法获取朋友列表。

你不能,这是他们的私人数据,所以它在他们的控制之下。如果他们想让应用程序访问它,他们会授予权限,它可以代表他们这样做。

Facebook好友列表只获取可标记的好友列表

Facebook不会访问完整的个人资料好友列表,它只显示您个人资料中的好友列表总数

pod和plist设置所有其他应用Facebook开发者步骤的设置

这是我在Swift 3.0可标记好友列表中的代码。

appdelegate.swift

import CoreData
import FBSDKCoreKit
import FBSDKLoginKit
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
         return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
        // Override point for customization after application launch.
        return true
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
    }
viewcontroller.swift

import UIKit
import FBSDKLoginKit
import FacebookCore
import FacebookLogin
import SDWebImage


class ViewController: UIViewController, FBSDKLoginButtonDelegate,UITableViewDelegate,UITableViewDataSource

{
    @IBOutlet var TblView: UITableView!
    @IBOutlet weak var btnFacebook: FBSDKLoginButton!

    @IBOutlet weak var ivUserProfileImage: UIImageView!

    @IBOutlet weak var lblName: UILabel!
    
     let reusableIdentifire = "cell"
    @IBOutlet var FriendListBtn: UIButton!
    
    var dict  = [AnyObject]()
    var FBNameArray = [String]()
    var FBImageArray = [String]()
    var Array = [String:AnyObject]()
    
    override func viewDidLoad()
    {
        super.viewDidLoad()
        self.TblView.delegate = self
        self.TblView.dataSource = self
        
      configureFacebook()
        
        //acess authorization 
        let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
        fbLoginManager.logIn(withReadPermissions: ["email"], from: self) { (result, error) in
            if (error == nil){
                let fbloginresult : FBSDKLoginManagerLoginResult = result!
                if fbloginresult.grantedPermissions != nil {
                    if(fbloginresult.grantedPermissions.contains("email"))
                    {
                        self.getFBUserData()
                        fbLoginManager.logOut()
                    }
                }
            }
        }
            self.TblView.reloadData()
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return FBNameArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {
        let cell: TableViewCell = self.TblView.dequeueReusableCell(withIdentifier: self.reusableIdentifire,for:indexPath) as! TableViewCell
        
        cell.FriendName.text = self.FBNameArray[indexPath.row]
        cell.FriendImg?.sd_setImage(with:URL(string: FBImageArray[indexPath.row] ), placeholderImage: UIImage(named: ""))

        //cell.FriendImg.image = UIImage(named: self.FBImageArray[indexPath.row])
        
        
        return cell
        
    }

    
    func configureFacebook()
    {
        btnFacebook.readPermissions = ["public_profile", "email", "user_friends"];
        btnFacebook.delegate = self
    }
    
    
    
    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
    {}
    
    func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!)
    {}
    
    func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!)
    {
        FBSDKGraphRequest.init(graphPath: "me", parameters: ["fields":"first_name, last_name, picture.type(large)"]).start { (connection, result, error) -> Void in
                       
            let strFirstName: String = ((result as AnyObject)["first_name"]) as! String
            let strLastName: String = ((result as AnyObject)["last_name"]) as! String
            let faceBookID:String = (result as AnyObject).value(forKey: "id") as! String
            let strPictureURL = String(format:"https://graph.facebook.com/%@/picture?type=large", faceBookID)
            
            self.lblName.text = "Welcome, \(strFirstName) \(strLastName)"
            self.ivUserProfileImage.image = UIImage(data: try! Data(contentsOf: URL(string: strPictureURL)!))
        }
    }
    private func loginButtonDidLogOut(loginButton: FBSDKLoginButton!)
    {
        let loginManager: FBSDKLoginManager = FBSDKLoginManager()
        ivUserProfileImage.image = nil
        lblName.text = "SignOut"

        loginManager.logOut()
        
           }
    
    func getFBUserData(){
        
        if((FBSDKAccessToken.current()) != nil){

            FBSDKGraphRequest(graphPath:"/me/taggable_friends", parameters:["fields":"user_id,first_name,last_name,name,picture.type(large)"],httpMethod: "GET")
                //["fields": "id, name, first_name, last_name, picture.type(large), email"])
                .start(completionHandler: { (connection,result, error) -> Void in
                if (error == nil)
                {
                    print("Friends are: \(result)")
                    let jsonResult = result as! Dictionary<String,AnyObject>
                    self.dict = jsonResult["data"] as! [AnyObject]
                    
                    for item in self.dict
                    {
                       // let id = item["id"] as! String
                        let name = item["name"] as! String
                        self.FBNameArray.append(name)
                        print("FBname: \(self.FBNameArray)")
                        let picture = item["picture"] as! NSDictionary
                        let parsePic = picture["data"] as! NSDictionary
                        let url = parsePic["url"] as! String
                        self.FBImageArray.append(url)
                        print("FBimage: \(self.FBImageArray)")
                        self.TblView.reloadData()
                    }
                    
                }
                    
            })
        }
    }

}
tableviewcell.swift

import UIKit

class TableViewCell: UITableViewCell
{

    @IBOutlet var FriendImg: UIImageView!
    @IBOutlet var FriendName: UILabel!
}

我想你不是在为那件事接受延长许可,为了得到延长许可我需要做什么????
import UIKit

class TableViewCell: UITableViewCell
{

    @IBOutlet var FriendImg: UIImageView!
    @IBOutlet var FriendName: UILabel!
}