-1

I am trying to access all the images form facebook that user uploaded I try it with user_photos

https://developers.facebook.com/docs/facebook-login/permissions/#reference-user_photos

I also try graph API explore from this iOS :How to get Facebook Album Photo's Picker

my code

for Login

  func btnFbClicked()
        {
        fbLoginManager.logOut()
        fbLoginManager.loginBehavior = .web
        fbLoginManager.logIn(withReadPermissions: ["public_profile", "email", "user_friends","user_photos"], from: self) { (result, error) in

        if error != nil
        {
        print("error occured with login \(String(describing: error?.localizedDescription))")
        }

        else if (result?.isCancelled)!
        {
        print("login canceled")
        }

        else
        {
        if FBSDKAccessToken.current() != nil
        {

        FBSDKGraphRequest.init(graphPath: "me", parameters: ["fields":"id, name, first_name, last_name, picture.type(normal), email,gender"]).start(completionHandler: { (connection, userResult, error) in

        if error != nil {

        print("error occured \(String(describing: error?.localizedDescription))")
        }
        else if userResult != nil {
        print("Login with FB is success")
        print(userResult as! [String:Any])

        self.fbData = (userResult as? NSDictionary)!

        let mutableFBDict = NSMutableDictionary(dictionary: self.fbData)
        print(mutableFBDict)


        if((mutableFBDict["email"] as? String) ?? "") == ""{


    //    self.showAlertNoHide(title: "", message: "If permission is granted then please set any email as a primary email in facebook general settings, then only facebook will return email to third party application. Sorry for the inconvenience.")

        return
        }


        var gender = Int64()
        if(mutableFBDict["gender"] as? String == "male")
        {
        gender = Int64(1)
        }
        else  if(mutableFBDict["gender"] as? String == "female")
        {
        gender = Int64(2)
        }
        else
        {
        gender = Int64(0)
        }



        self.fetchListOfUserPhotos()
}

for fetching Photos

func fetchListOfUserPhotos()
    {
        guard let id  = self.fbData["id"] as? String else
        {
            return
        }
        let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: id + "/photos" , parameters: ["fields":"user_photos"], httpMethod: "GET")


        //FBSDKGraphRequest(graphPath: id + "/photos" , parameters: nil, httpMethod: "GET")

        graphRequest.start(completionHandler: { (connection, result, error) -> Void in

            if ((error) != nil)
            {
                // Process error
                print("Error: \(error)")
            }
            else
            {
                print("fetched user: \(result)")

                let fbResult:[String:AnyObject] = result as! [String : AnyObject]

                self.userPhotos = fbResult["data"] as! NSArray?

                self.myCollectionView.reloadData()

            }
        })
    }

Respons I get

Optional({
    data =     (
    );
})

so my question is can access images that user uploaded on facebook or facebook change policies?

balkaran singh
  • 2,754
  • 1
  • 17
  • 32

1 Answers1

0
"fields":"user_photos"

user_photos is a permission, not a field for API requests. About the existing fields for photos, check out the API reference: https://developers.facebook.com/docs/graph-api/reference/photo/

If you don´t get any photos, debug your Access Token and make sure it really is a User Token that includes the user_photos permission: https://developers.facebook.com/tools/debug/accesstoken/

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • i already set the permission fbLoginManager.logIn(withReadPermissions: ["public_profile", "email", "user_friends","user_photos"], from: self) { (result, error) in if error != nil { print("error occured with login \(String(describing: error?.localizedDescription))") } else if (result?.isCancelled)! { print("login canceled") } – balkaran singh May 27 '19 at 07:39
  • i also try with let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me/photos", parameters: nil ) but it's not work for me. – balkaran singh May 27 '19 at 07:41
  • you still need to debug the access token to make sure you´ve authorized correctly. the response looks like user_photos is not authorized. – andyrandy May 27 '19 at 07:55
  • can you plz let me know how to authorized for user_photos ? – balkaran singh May 27 '19 at 10:55
  • i thought that´s what you tried already? do you even get asked for the requested permissions? and did you debug the access token, as i have pointed out? – andyrandy May 27 '19 at 11:26