有人可以帮我吗?
我在Facebook上注册并设置为“直播”的应用程序有appID,秘密和令牌客户端。 从我的应用程序,userA在Facebook上执行登录,我得到了IdA(这是app-scoped)。 从我的应用程序,userB在Facebook上执行登录,我得到了仍然应用范围的IdB。
现在,每当我尝试获取用户个人资料图片时,我都会收到错误消息。 这是我为用户A尝试的,对用户B也是如此:
https://graph.facebook.com/IdA/picture?type=small&access_token=appID|secret “message”:“不支持的get请求。具有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访问令牌。”, “type”:“OAuthException”, “代码”:190 https://graph.facebook.com/IdA/picture?access_token=Token客户 “message”:“无效的OAuth访问令牌。”, “type”:“OAuthException”, “代码”:190
有人可以对此有所了解吗? 提前致谢
答案 0 :(得分:0)
您需要授予权限,之后,您需要调用图形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"])
}
}
}
}