iamburak
iamburak

Reputation: 3568

Facebook SDK access token issue with Xcode 9.3

I have just updated phone iOS11.3 and Xcode 9.3, facebook login goes crash like this from my old SDK call:

https://pasteboard.co/HeeRDVo.png

I didn't understand what that mean exactly, even it works with older versions. Then I applied Swift SDK from that page, https://developers.facebook.com/docs/swift/graph.

import FacebookCore

let connection = GraphRequestConnection()
connection.add(GraphRequest(graphPath: "/me")) { httpResponse, result in
  switch result {
  case .success(let response):
    print("Graph Request Succeeded: \(response)")
  case .failed(let error):
    print("Graph Request Failed: \(error)")
  }
}
connection.start()

That gives below error log:

FBSDKLog: starting with Graph API v2.4, GET requests for //me should contain an explicit "fields" parameter
Graph Request Failed: 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" = ____id____;
            message = "An active access token must be used to query information about the current user.";
            type = OAuthException;
        };
    };
    code = 400;
}}

It says, An active access token must be used to query information about the current user.

Even below code block gives same error when I made dictionaries comment line, because they don't work also.

import FacebookCore

struct MyProfileRequest: GraphRequestProtocol {
  struct Response: GraphResponseProtocol {
    init(rawResponse: Any?) {
      // Decode JSON from rawResponse into other properties here.
    }
  }

  var graphPath = "/me"
  var parameters: [String : Any]? = ["fields": "id, name"]
  var accessToken = AccessToken.current
  var httpMethod: GraphRequestHTTPMethod = .GET
  var apiVersion: GraphAPIVersion = .defaultVersion
}


let connection = GraphRequestConnection()
connection.add(MyProfileRequest()) { response, result in
  switch result {
  case .success(let response):
    print("Custom Graph Request Succeeded: \(response)")
    print("My facebook id is \(response.dictionaryValue?["id"])")
    print("My name is \(response.dictionaryValue?["name"])")
  case .failed(let error):
    print("Custom Graph Request Failed: \(error)")
  }
}
connection.start()

What should I do to overcome this issue?

Upvotes: 1

Views: 1962

Answers (1)

iamburak
iamburak

Reputation: 3568

Finally I have solved my problem using below method instead of annotation open url method in the AppDelegate. Hope that it helps others who encounter with this problem in iOS 11.3.

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(app,
                                                                     open: url,
                                                                     sourceApplication: options[.sourceApplication] as! String,
                                                                     annotation: options[.annotation])
    }

Upvotes: 13

Related Questions