SWIFT - FBSDKLoginManager error when using FB App - ios

I'm using the FBSDKLoginManager to receive a token for later usage (FB posting) and end up in an endless loop after confirming the access.
When calling the FBSDKLoginManager(), the following popup appears (Sorry, it's in German language... This is the official Facebook popup, where the user can select whether he wants to logon manually or using the FB App).
Now the following error occurs:
If I'm using the second button (logon via phone number or E-Mail-Address), everything works fine. The function returns with a token and I can go on in my App.
The ERROR: If I'm using the first button (logon with Facebook-App), the Facebook App opens, I can set all the privacy settings in FB, and confirm. After confirming the access, the FB-App closes automatically and returns to the same popup-screen without any change. No action occurs after coming back to this screen...
I don't have any foggy idea where the problem is... There is no error message. Due to the fact that everything works fine when using the E-Mail Login, the problem must be in the return of the FB-App. The E-Mail Login works via Safari, in the error case there is the break to the FB-App.
let login: FBSDKLoginManager = FBSDKLoginManager()
login.logIn(withPublishPermissions: ["publish_actions"], from: self) { (result, error) in
if (error != nil) {
print("publish_actions: \(error!)")
} else if (result?.isCancelled)! {
print("publish_actions: Canceled")
} else if (result?.grantedPermissions.contains("publish_actions"))! {
//print("publish_actions: permissions granted: \(String(describing: result?.token.tokenString))")
UserDefaults.standard.set(result?.token.tokenString, forKey: "facebook_token")
}
Added Frameworks: Bolts / CoreKit / LoginKit
Development Environment: Xcode 9.2 / iPhone 6s with iOS 11.2 / latest Facebook App installed.

I solved by adding the follow missing call to FB SDK:
[[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
inside
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation method of the AppDelegate.

Check for following
in your info plist file
<key>FacebookAppID</key>
<string>fb_id_here</string> // in format 234234234
<key>FacebookDisplayName</key>
<string>display_name_here</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>fbfb_id_here </string>. // in format fb234234234
</array>
</dict>
</array>
now inyour appdelegate
in
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
if let scheme = url.scheme {
if scheme == "fb 234234234" { //the one you kept in your info plist file
//TODO: replace with real value
return SDKApplicationDelegate.shared.application(application, open: url, options: options)
}
}
return true
}
Do configure these and then dub your app, if the control folw comes in appdelegate function
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool
if it doesnt you have not configured facebook schemas correctly in info plist file
also
let fbManager = FBSDKLoginManager()
fbManager.logOut()
let readPermissions: [ReadPermission] = [.publicProfile, .email]
let sdkPermissions = readPermissions.map({ $0.permissionValue.name })
fbManager.logIn(withReadPermissions: sdkPermissions, from: nil) { (result, error) in
if let token = result?.token {
// your token here
}
else {
}
}

Thank you very much. This solved the problem.
1.) The plist file was already set up. I think otherwise the login with Safari wouldn't have worked.
2.) The App Delegate was the reason!!! Small adjustment:
SDKApplicationDelegate.shared didn't work. I should be as followed:
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
(As well in the added "application-open URL"-function.)
But now it works. Thanks a lot.

i think maybe i found an one issue, in my xcode, AppDelegate's
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool , xcode fix this function to private, and i fixed this function to internal, it will works~

Related

Facebook iOS SDK login error (Invalid Scopes: public_profile, openid.)

I receive the follow error when trying to login using the iOS Facebook SDK:
Invalid Scopes: public_profile, openid.
I have followed the instructions from here which has resulted in this set up:
info.plist
<plist version="1.0">
<dict>
...
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>GOOGLE_URL_SCHEME</string>
<string>fbMY_FB_APP_ID</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>MY_FB_APP_ID</string>
<key>FacebookClientToken</key>
<string>MY_FB_CLIENT_TOEN</string>
<key>FacebookDisplayName</key>
<string>MY_FB_APP_NAME</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbauth2</string>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
</array>
</dict>
</plist>
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
ApplicationDelegate.shared.application( application, didFinishLaunchingWithOptions: launchOptions )
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
return ApplicationDelegate.shared.application(app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])
}
Login snippet
let loginManager = LoginManager()
loginManager.logIn(permissions: ["public_profile"], from: self) { result, error in
if let error = error {
print("FB Error: \(error)")
} else if let result = result, result.isCancelled {
print("FB Cancelled")
} else {
print("FB Logged In")
}
}
I am on iOS 16.2 using the facebook-ios-sdk version 15.1.0. The same error occurs with FB app in live and development mode. I receive the same error on the simulator and device. I can successfully login on the web when using the FB app JS library. I believe I have followed the instructions correctly. What am I missing?
Edit: Settings Screenshots
Edit:
So I just downloaded this sample from the facebook-ios-sdk. Added my FB App Id to the FacebookAppID field and URL Schemes in the plist. Added the FB Client Token to the plist and updated the bundle identifier to the one listed in the Facebook app, but I get the same error when I run the sample. What the hell is going on? The issue must be in the Facebook app set up, but where? I can't find this issue reported anywhere on the net. Surely someone has seen this before.
I figured it out. I was missing the facebook login from my facebook app products. I found it by accident and now I can login successfully.

Logging in through Facebook not working for my iOS app [duplicate]

This question already has answers here:
iOS Facebook Login "Given URL is not allowed by the Application configuration"
(3 answers)
Closed 3 years ago.
My app has a setup where users can log in normally through Email and Password entry or through their Facebook login credentials.
For handling log in through Facebook, I am using Facebook dependencies through Cocoapods. Also I had recently updated these dependencies.
Podfile Snippet:-
pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'
My Podfile.lock Snippet:-
- FacebookCore (0.5.0):
- Bolts (~> 1.9)
- FBSDKCoreKit (~> 4.37)
- FacebookLogin (0.5.0):
- Bolts (~> 1.9)
- FacebookCore (~> 0.5)
- FBSDKCoreKit (~> 4.37)
- FBSDKLoginKit (~> 4.37)
- FacebookShare (0.5.0):
- Bolts (~> 1.9)
- FacebookCore (~> 0.5)
- FBSDKCoreKit (~> 4.37)
- FBSDKShareKit (~> 4.37)
- FBSDKCoreKit (4.38.1):
- Bolts (~> 1.9)
- FBSDKLoginKit (4.38.1):
- FBSDKCoreKit
- FBSDKShareKit (4.38.1):
- FBSDKCoreKit
Users can log in using their Facebook credentials on through the Facebook website through Safari browser using the email/phone number password credentials
The problem comes when users try to log in through the Facebook App in their iPhones.
These are the screenshots of the problem at hand.
The first Screenshot shows the facebook login page through my app:-
The next Screenshot shows the error when trying to log in through the facebook app:-
While searching for a solution, I came across this post:-
Similar post
And based on this post, I checked my info.plist. it seems valid
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>fb{facebook-app-id}</string>
</array>
</dict>
</array>
...
<key>FacebookAppID</key>
<string>{facebook-app-id}</string>
<key>FacebookDisplayName</key>
<string>{facebook-display-name}</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>whatsapp</string>
</array>
This is the code I have for Facebook-related Login in the login view controller:-
func facebookLoginButtonClicked(sender: UIButton) {
let loginManager = LoginManager()
loginManager.logIn(readPermissions: [ReadPermission.publicProfile, ReadPermission.email], viewController : self) { loginResult in
switch loginResult {
case .failed(let error):
print(error)
case .cancelled:
print("User cancelled login")
case .success(let grantedPermissions, let declinedPermissions, let accessToken):
if let token = accessToken.authenticationToken ?? nil{
let params = ["access_token": token as AnyObject, "account_type": PineSimpleData.getOnboardingAccountType()! as AnyObject]
let url = "/user/connect/facebook"
self.socialLogin(params: params, url: url)
}
}
}
}
Code Snippets in the AppDelegate:-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
....
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
var handled = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
if handled {
return true
}
....
return handled
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options) {
return true
}
....
return true
}
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
Logging in through both the app and the Facebook website was working fine until now. How should I handle this error? Has something been made mandatory in the facebook developers section? If so, what am I supposed to change in the facebook developer page? Any help is appreciated.
below are the basics steps:-
1.Open https://developers.facebook.com and select your app
2.Settings > Basic > Add Platform
3.Now select iOS from the window and add your Bundle ID and rest of the information and click on Save changes.
same problem you can check it here:- iOS Facebook Login "Given URL is not allowed by the Application configuration"
Facebook application query is only fb.
You need to update your plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>whatsapp</string>
</array>
There is a toggle in facebook developer dashboard which determines whether the app is native or not.
May be you forgot to turn if on.
Check this image for exact location of that setting

Fast App Switch iOS 11 Facebook Login

Currently my facebook login does the following:
Tap the login with fb button
Asks for permission to to use "facebook.com" to log in
Asks whether to use app or log in with an email or phone in a Safari View Controller
If selected app: Asks to open Facebook app
Asks for permission to let the fb app use your to log in
Returns to app
Those are too many steps for me. I'd like to do something like Uber app, it's facebook login flow is:
Tap the login with fb button
Asks to open Facebook app
Asks for permission to let the fb app use your account to log in
Returns to app
Uber's flow:
Facebook Fast App Switch
There's an article that says theres a Fast App Switch way to login which is what I want for my app, If facebook app is installed I want the login to be done directly to the app.
I've used this code at my sign in button action with no luck:
let fbLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = .native
fbLoginManager.logIn(withReadPermissions: ["public_profile", "email"], from: self) { (result, error) in
let credential = FacebookAuthProvider.credential(withAccessToken: accessToken.tokenString)
// Perform login by calling Firebase APIs..
}
At my Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fbXXXXXXXX</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>XXXXXXXX</string>
<key>FacebookDisplayName</key>
<string>My Beautiful App</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
At my AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions:launchOptions)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
return handled
}
Facebook SDK version: 4.27.1
Using FBSDKCoreKit (4.27.1)
FBSDKLoginKit (4.27.1)
FBSDKShareKit (4.27.1)

App Invites facebook | not getting notification on iOS but getting in android however invitation is listed in facebook -> apps -> app invites

I had added facebook app invite feature in my app below is my code sending app invitations
let content = FBSDKAppInviteContent()
content.appLinkURL = NSURL(string: "applinkurl")
content.appInvitePreviewImageURL = NSURL(string: "appInvitePreviewImageURL")
FBSDKAppInviteDialog.showWithContent(content, delegate: self);
I had added below extension to the class
extension FACEBOOKTEXT:FBSDKAppInviteDialogDelegate {
//MARK: FBSDKAppInviteDialogDelegate
func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [NSObject : AnyObject]!) {
print("invitation made")
}
func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: NSError!) {
print("error made")
}
in app delegate :
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
var shouldReturn:Bool = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation);
shouldReturn = shouldReturn || GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation);
shouldReturn = shouldReturn || Instagram.sharedManager().handleOpenURL(url);
shouldReturn = shouldReturn || LinkedInBridge.handleURL(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation);
return shouldReturn;
}
I had configured the "App Links" from facebook portal nd put it in infi.plist and content.appLinkURL.
On running this code the app invitations are sent. And when the receiver of the app invitation is on android the invitation is listed in the notification feel of the facebook and use is able to install app via it. But if the receiver of the invitation is on iOS the invitation is not listed in the notification feed of the use however if the user goes to facebook -> More(tab) -> apps -> App invites, here the invitation is listed.
Please guide me where I am doing wrong. and what should I do to list invitations in notification in iOS same like android.
I am using Xcode 6.4 and Swift 1.2
this is working for iOS 8 but not working for iOS 9
Thanks in advance,
add below URL schemes to your info.plist for make it work in iOS 9
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbapi20160328</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
<string>fb-messenger-platform-20150128</string>
<string>fb-messenger-platform-20150218</string>
<string>fb-messenger-platform-20150305</string>
<string>fb-messenger-api</string>
<string>fbshareextension</string>
</array>
additionally do below two things
1. Open facebook.com -> Settings -> apps -> delete your app if already given permissions to the app
Open mobile facebook app -> tap on More(last tab) -> apps -> app invites -> delete if any app invite is already there.
Hope this will work for you.

Authenticating with FlickrKit for iOS

I am using FlickrKit to attempt to login to my Flickr account for iOS (iPhone 5 simulator).
A) I specified the following for [[FlickrKit sharedFlickrKit] initializeWithAPIKey:]
- Flickr Key
- Flickr Secret
B) Then I called [[FlickrKit sharedFlickrKit] beginAuthWithCallbackURL:]
- where the callback URL is #"MyTestApp://auth".
- "MyTestApp" is defined under URL Types -> Item 0 -> URL Schemes -> Item 0.
C) Unfortunately after the logging in process, I get this error when I try to login using FlickrKit for iOS.
"An external application has asked to link to your Flickr account, but
failed to include all the necessary information. Specifically:"
(then I see a black bar, so I have no idea what the specific error is).
See screenshot below:
Any ideas?
Are you having to press the "OK, I'LL AUTHORIZE IT" button twice, with this black bar appearing the second time?
I believe what is happening is that you select the "authorize" button, which then sends the callback to your app, but when you select that button again Flickr thinks you are trying to use a duplicate auth token and wont allow it.
As a quick check, implement this method in your app delegate:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
Then throw an NSLog in there to see what the url is that is being passed. You'll probably get the data you were looking for.
I ran into this problem earlier today and was incredibly frustrated by it.
So for the latest version of swift I had to do the following:
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
if (url.host == "oauth-callback") {
OAuth1Swift.handleOpenURL(url)
}
return true
}
Also my plist needed the following:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>my.bundle.id</string>
<string>oauth-swift</string>
</array>
<key>CFBundleURLName</key>
<string></string>
</dict>
</array>
But that is because I was using the following library: https://github.com/dongri/OAuthSwift
This is coming over a year late. I was able to make it work by making sure the all the info.plist was well configured (with the right schemes. The previous dev removed it. But, it worked fine then.) and also, I override a function in my AppDelegate class. func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool and did this
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("DictionaryScheme: ", url.scheme!)
if url.scheme == "schemename" {
NotificationCenter.default.post(name: Notification.Name(rawValue: "UserAuthCallbackNotification"), object: url)
return true
}
return false
}

Resources