FBSDKGraphRequest 使用未声明的标识符

FBSDKGraphRequest use of undeclared identifier

虽然我已经像这样导入了 FacebookSDK:#import <FacebookSDK/FacebookSDK.h>,但它说: 使用未声明的标识符 'FBSDKGraphRequest'.

我写的代码很简单:

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                      initWithGraphPath:@"/{user-id}/albums"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                              id result,
                                              NSError *error) {
            // Handle the result
        }];

让我知道我可能遗漏了什么?

要使用新的 SDK 4.1 登录 Facebook,您必须在项目中添加 FBSDKLoginkit 和 FBSDKCoreKit 框架。

然后将下面的头文件导入你的 ViewController:

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

更多信息你可以参考the facebook official document here或者你可以参考这些答案

虽然facebook官方文档最好

自版本 4.X 起,Facebook 将 SDK 分为 3 个部分:

Per documentation:

The SDK is now composed of three frameworks, FBSDKCoreKit, FBSDKLoginKit, and FBSDKShareKit.

FBSDKCoreKit provides core SDK functionality such as Graph API Requests, access tokens, and App Insights.

FBSDKLoginKit provides functionality to log people in, and only requires FBSDKCoreKit.

FBSDKShareKit provides functionality to share, and only requires FBSDKCoreKit.

关于你的问题:

Requests - FBSDKGraphRequest and FBSDKGraphRequestConnection are in FBSDKCoreKit and provide helpers to access the Graph API

所以基本上你需要在你的文件中导入 FBSDKCoreKit:

#import <FBSDKCoreKit/FBSDKCoreKit.h>