Facebook SDK for iOS Access Token Issue

时间:2015-11-28 02:27:08

标签: ios facebook swift

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

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

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

package cyanlauncher;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;


public class Main extends Application {
    private int numApps = 0;
    private float btnSize = 48;
    private float btnSpacing = 12;
    @Override
    public void start(Stage primaryStage) {
            primaryStage.initStyle(StageStyle.TRANSPARENT);
            primaryStage.setTitle("CyanLauncher");

            Button quitBtn = new Button();

            Pane  root = new Pane();
            root.getChildren().add(addHBox());

            quitBtn.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("./../data/exit.png"))));
            quitBtn.setLayoutX(10 + ((btnSize + btnSpacing) * numApps));
            quitBtn.setLayoutY(7);
            quitBtn.setPadding(new Insets(0,0,0,0));
            quitBtn.setPrefSize(btnSize, btnSize);
            quitBtn.setOnAction(new EventHandler<ActionEvent>(){

                @Override
                public void handle(ActionEvent event){
                    System.exit(0);
                }

            });

            root.getChildren().add(quitBtn);


            Scene scene = new Scene(root,64,64);


            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            scene.setFill(null);

            primaryStage.setScene(scene);
            primaryStage.show();
    }

    public HBox addHBox() {
        HBox hbox = new HBox();
        hbox.setPrefSize(64, 64);
        hbox.setLayoutX(10);
        hbox.setLayoutY(7);  
        return hbox;
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Podfile

/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
.root {
     -fx-background-color: rgba(0,255,0,1);
}

.button {
     -fx-background-color: rgba(0,0,255,1);
}

.hbox {
    -fx-background-color: rgba(255,0,0,1);
}

ViewController with FBSDKLoginButtonDelegate

-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;
}}

App Delegate

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'

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

如果您有任何建议可以解决此问题。

1 个答案:

答案 0 :(得分:6)

我的错误是我的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