简体   繁体   English

适用于iOS的Facebook SDK访问令牌发行

[英]Facebook SDK for iOS Access Token Issue

I am trying to use Facebook in my iOS swift application to get some basic user information. 我试图在我的iOS swift应用程序中使用Facebook来获取一些基本的用户信息。 I used Cocoapods to install the Facebook dependencies. 我使用Cocoapods安装了Facebook依赖项。 I have updated my info.plist using the following links. 我已经使用以下链接更新了info.plist。

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

I receive the following compiler errors whenever I try logging in through facebook: 每当我尝试通过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;
}}

Podfile 播客文件

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'

ViewController with FBSDKLoginButtonDelegate 带FBSDKLoginButtonDelegate的ViewController

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)")
            }
        })
}

App 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()
}

Other Information: Swift 2, Xcode 7, iOS 9 其他信息:Swift 2,Xcode 7,iOS 9

Any suggestions would be appreciated to resolve this issue. 任何建议将不胜感激以解决此问题。

My mistake was that I had both of the following functions within my AppDelegate. 我的错误是我的AppDelegate中同时具有以下两个功能。 openURL method with sourceApplication is deprecated so the application would use the updated method. 不推荐使用带有sourceApplication的openURL方法,因此应用程序将使用更新的方法。 However, Facebook's own documentation states to use the deprecated version which lead to my mistake located here: https://developers.facebook.com/docs/ios/getting-started 但是,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 Stating to Use Deprecated openURL http://imgur.com/kwI5VId Facebook声明使用已弃用的openURL http://imgur.com/kwI5VId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM