当前位置: 首页 > 知识库问答 >
问题:

正确使用facebook应用范围的用户ID

龚奇逸
2023-03-14

有人可以帮我吗?

我的应用程序,在Facebook上注册并设置为“实时”,有一个应用程序ID,一个密钥和一个令牌客户端。在我的应用程序中,用户A在脸书上执行登录,我得到IdA(这是应用程序范围的)。在我的应用程序中,用户B在Facebook上执行登录,我得到的IdB仍然是应用程序范围的。

现在,每当我尝试获取用户配置文件图片时,都会出现错误。这是我为用户A尝试的,用户B也一样:

https://graph.facebook.com/IdA/picture?type=small

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

有人能解释一下吗?提前谢谢

共有1个答案

傅英喆
2023-03-14

您需要授予权限,然后需要调用图形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"])
            }

        }
    }
}
 类似资料:
  • 本文向大家介绍Nginx 应用范围和使用详解,包括了Nginx 应用范围和使用详解的使用技巧和注意事项,需要的朋友参考一下 Nginx 应用详解 前言 本文只针对Nginx在不加载第三方模块的情况能处理哪些事情,由于第三方模块太多所以也介绍不完,当然本文本身也可能介绍的不完整,毕竟只是我个人使用过和了解到过得。所以还请见谅,同时欢迎留言交流 Nginx能做什么 1.反向代理 2.负载均衡 3.HT

  • 对于,使用C 11基于范围的的正确方法是什么? 应该使用什么语法<代码>用于(自动元素:容器),或

  • 我正在客户端使用带有标准Facebook登录按钮的Facebook Javascript SDK。当用户单击按钮时,我会从Facebook获得用户id。稍后,我将从服务器端使用Facebook PHP SDK。我想检查用户id是否是真实的用户id。我搜索了一些资源,但我不知道我的方法是否正确。我使用访问令牌。我的链接在上面。当我发送请求时,收到一个错误。客户端id是我的应用程序id,客户端机密是密

  • 我一直在探索构建我的ColdFusion应用程序的不同方法,我正在寻找一些关于提供应用范围UDF的最佳方式的意见。 对于我的每一个应用程序,我通常都会使用一些不属于任何特定对象的额外功能。主要是数据操作。我希望这些功能在我的整个应用程序中都可用,既可以在CFM模板中使用,也可以在应用程序实例化的CFC中使用。 在我看来,有各种各样的方法来实现这一点,但它们都有自己的局限性: > 创建一个基本的Ut

  • 问题:给定二叉查找树的根节点,返回值在L和R(包括)之间的所有节点的值之和。 二叉搜索树保证具有唯一的值。 例1: 输入:root=[10,5,15,3,7,null,18],L=7,R=15 输出: 32 Leetcode问题:https://leetcode.com/problems/range-sum-of-bst/ 我的方法是:我尝试执行dfs并访问每个节点,如果该节点上的值符合约束条件,

  • 只是想寻求一点帮助!我现在正在做一个体重转换项目。我已经让它正常工作了,但现在我正试图让它成为傻瓜式的,也就是说,如果用户输入的数值低于或超过某个范围(在本例中,我寻找的是0到450之间的KG),则会出现一条消息,告知错误,然后会提示用户再次输入其值。我可以用下面的代码实现这一点,但问题是,当用户输入一个有效值时,它不仅会打印有效输入的转换,还会打印之前不正确的值的转换。我附上了一个命令提示符的屏