NA000022 NA000022 - 6 months ago 15
Swift Question

Not getting photos from Facebook

I want to fetch all the photos from facebook account. But I am unable to fetch it. Whenever i request I get empty array.

@IBAction func shareFacebook(sender: FBSDKLoginButton) {
sender.readPermissions = ["public_profile", "email", "user_friends"]
sender.delegate = self
sender.loginBehavior = .Native
}

//Delegate Method
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
{
print(result.token)
FBSDKGraphRequest.init(graphPath: "me/photos", parameters: ["fields":"age_range,name,first_name, last_name, picture.type(large)"], HTTPMethod: "get").startWithCompletionHandler { (con, res, err) in
print(res)
}
}

//Output = <FBSDKAccessToken: 0x12fea99a0>
{
data = (
);
}

Answer

/me/photos requires the permission user_photos. Make sure you authorize the user with that permission:

sender.readPermissions = ["public_profile", "email", "user_friends", "user_photos"]

If it still does not work, make sure you are trying as App Admin and read about Login Review: https://developers.facebook.com/docs/facebook-login/review

Also, the /me/photos endpoint does not have fields like age_range, name, first_name and so on. That would be the /me endpoint only.

Comments