gpt4 book ai didi

ios - Facebook SDK for iOS 访问 token 问题

转载 作者:搜寻专家 更新时间:2023-11-01 05:57:55 25 4
gpt4 key购买 nike

我正在尝试在我的 iOS swift 应用程序中使用 Facebook 来获取一些基本的用户信息。我使用 Cocoapods 安装 Facebook 依赖项。我已经使用以下链接更新了我的 info.plist。

https://developers.facebook.com/docs/ios/ios9 https://developers.facebook.com/quickstarts/115956755431487/?platform=ios

每当我尝试通过 facebook 登录时,我都会收到以下编译器错误:

-canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
-canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
Error: Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 2500;
"fbtrace_id" = F1CmQQhd4pA;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}}

播客文件

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
pod 'FBSDKCoreKit', '~> 4.8'
pod 'FBSDKLoginKit', '~> 4.8'
pod 'FBSDKShareKit', '~> 4.8'

带有 FBSDKLoginButtonDelegate 的 View Controller

override func viewDidLoad() {
super.viewDidLoad()
var loginButton = FBSDKLoginButton()
loginButton.readPermissions = ["user_about_me", "email", "public_profile"]
loginButton.center = self.view.center
loginButton.delegate = self
self.view.addSubview(loginButton)
}

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
let fields = "email, name, first_name, last_name"
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : fields])
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil) {
print("Error: \(error)")
}
})
}

应用委托(delegate)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}

其他信息:Swift 2、Xcode 7、iOS 9

如果有任何建议可以解决此问题,我们将不胜感激。

最佳答案

我的错误是我的 AppDelegate 中有以下两个函数。不推荐使用带有 sourceApplication 的 openURL 方法,因此应用程序将使用更新后的方法。然而,Facebook 自己的文档声明使用已弃用的版本,这导致我的错误位于此处:https://developers.facebook.com/docs/ios/getting-started

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
}

Facebook 声明使用已弃用的 openURL http://imgur.com/kwI5VId

关于ios - Facebook SDK for iOS 访问 token 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33967036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com