【问题标题】:Correct use of facebook app-scoped user id正确使用 facebook 应用范围的用户 ID
【发布时间】:2018-10-15 14:29:58
【问题描述】:

有人可以帮我吗?

我在 Facebook 上注册并设置为“实时”的应用程序有一个 appID、一个秘密和一个令牌客户端。 从我的应用程序中,userA 在 Facebook 上执行登录,我得到 IdA(它是应用程序范围的)。 在我的应用中,userB 在 Facebook 上执行登录,而 IdB 仍然是应用范围内的。

现在,每当我尝试获取用户个人资料图片时,都会出现错误。 这是我为用户 A 尝试的,对用户 B 也是如此:

https://graph.facebook.com/IdA/picture?type=small&access_token=appID|secret "message": "不支持获取请求。ID 为 'IdA' 的对象不存在,由于缺少权限而无法加载,或者不支持此操作。请阅读https://developers.facebook.com/docs/graph-api 的 Graph API 文档", "type": "GraphMethodException", “代码”:100, “error_subcode”:33

https://graph.facebook.com/IdA/picture?access_token=appID "message": "无效的 OAuth 访问令牌。", “类型”:“OAuthException”, “代码”:190 https://graph.facebook.com/IdA/picture?access_token=Token客户 "message": "无效的 OAuth 访问令牌。", “类型”:“OAuthException”, “代码”:190

有人可以解释一下吗? 提前致谢

【问题讨论】:

    标签: swift facebook


    【解决方案1】:

    您需要授予权限,然后,您需要调用图形 API (FBSDKGraphRequest) 来获取个人资料图片。 我准备了一堂课,你可以从这堂课中达到你的要求:

    import UIKit
    import FBSDKCoreKit
    import FacebookCore
    import FacebookLogin
    
    class LoginWithFacebook {
    
        // MARK: - Properties
        static let sharedInstance = LoginWithFacebook()
    
    
        /**
         Takes user to the facebook login page so that user could login with his facebook credentials and brings back basic details of the user and photo album
         - parameter viewControl: controller on which the facebook page will be opened
         - parameter completion: on completion the method returns user info in the form of dictionary
         */
        public func fBLoginWithPhotoAlbum(viewControl: UIViewController, completion: @escaping ([String: Any]) -> Void) {
    
            var responseDictionary: [String: Any] = [String: Any]()
            let loginManager = LoginManager()
    
            loginManager.logIn(readPermissions: [.publicProfile, .email, .userFriends, .custom("user_birthday")], viewController: viewControl) { (loginResult) in
                print(loginResult)
                switch loginResult {
                case .failed(let error):
                    print(error)
    
                case .success(grantedPermissions: _, declinedPermissions: _, token: let accessToken) :
    
                    responseDictionary.updateValue(accessToken.authenticationToken, forKey: "accessToken")
    
                    let param = ["fields": "first_name, last_name, picture.width(9999), email, friends, gender, age_range, birthday, photos{album,picture}"]
                    FBSDKGraphRequest.init(graphPath: "me", parameters: param).start { (_, result, _) -> Void in
    
                        if let resultDictionary: NSDictionary = result as? NSDictionary {
                            responseDictionary.updateValue(resultDictionary, forKey: "userInfo")
    
                            FBSDKGraphRequest.init(graphPath: "me/albums", parameters: ["fields": "photos{picture}"], httpMethod: "GET").start(completionHandler: { (_, result, _) in
    
                                let data = (result as? NSDictionary)?.value(forKey: "data") as? NSArray
                                if (data?.count)! > 0 {
                                    var profileAlbum: [Any] = data!.filter { NSPredicate(format: "(name == %@) ", "Profile Pictures").evaluate(with: $0) }
                                    if profileAlbum.count > 0 {
                                        if let profilePicAlbum = profileAlbum[0] as? NSDictionary {
                                            let graphPath = profilePicAlbum.value(forKey: "id")
    
                                            //picture, "photos{link}"
                                            let param = ["fields": "photos{picture}"]
                                            FBSDKGraphRequest.init(graphPath: graphPath as? String, parameters: param, httpMethod: "GET").start(completionHandler: { (_, result, _) in
                                                if let profilePicArray = (result as? NSDictionary)?.value(forKeyPath: "photos.data") {
                                                    responseDictionary.updateValue(profilePicArray, forKey: "profilePics")
                                                    completion(responseDictionary)
                                                }
                                            })
                                        }
                                    }
                                } else {
                                    completion(responseDictionary)
                                }
                            })
    
                        } else {
    
                        }
                    }
    
                case .cancelled :
                    completion(["message": "Something Went Wrong"])
                }
    
            }
        }
    }
    

    【讨论】:

    • 非常感谢 Jogendar,但我想这不是我要找的,我的需要与相册无关,我只想从我的应用程序中获取 facebook 用户的个人资料图片-范围内的用户 ID。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多