Facebook Account Kit SDK gives invalid OAuth 2.0 error - swift

I have integrated Account kit sdk in to my project.
I created the application on facebook development dashboard, enabled Account Kit on it. Got app-id and client access token.
I added it into info.plist file. I am getting this error:
[AccountKit][Error]: Invalid OAuth 2.0 Access Token
2016-05-31 02:41:32.191 Chat[2919:563260] [AccountKit][Error]:
Persisting App Events due to error:
Error Domain=com.facebook.accountkit:Error Code=200 "(null)"
UserInfo={com.facebook.accountkit:ErrorDeveloperMessageKey=Invalid OAuth access token., NSUnderlyingError=0x147596a30
{Error Domain=com.facebook.accountkit:ServerError Code=190 "(null)" UserInfo={com.facebook.accountkit:ErrorDeveloperMessageKey=Invalid OAuth access token.}}}
Please need help. Thanks

Make sure you have the correct settings in info.plist.
I had a similar problem and in my case it was missing a key FacebookAppID
<key>FacebookAppID</key>
<string>{your-app-id}</string>
<key>AccountKitClientToken</key>
<string>{your-account-kit-client-token}</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>ak{your-app-id}</string>
</array>
</dict>
</array>

Make sure that initialization response type of AKFAccountKit matches with your application dashboard configuration.
It can be:
accountKit = [[AKFAccountKit alloc] initWithResponseType:AKFResponseTypeAccessToken];
or
accountKit = [[AKFAccountKit alloc]initWithResponseType:AKFResponseTypeAuthorizationCode];

This might be an issue with your configuration. You can file a bug report with Facebook here including your token information: https://developers.facebook.com/bugs/

I got this error when I had copied the wrong AccountKitClientToken into the Info.plist. Got the right one in there and everything is working now!

You can add your client token using AKFSettings.setClientToken("MY TOKEN") and make sure to import AccountKit at the top of the file where you call this.

Related

Firebase Google SignIn failed - "Audience Mismatch"

I have implemented Google sign in via Firebase and followed proper documentation: https://firebase.google.com/docs/auth/ios/firebaseui
I am using,
- FirebaseUI/Auth (8.5.1):
- Firebase/Auth (~> 6.0)
- GoogleUtilities/UserDefaults
- FirebaseUI/Google (8.5.1):
- FirebaseUI/Auth
- GoogleSignIn (~> 5.0)
COCOAPODS: 1.9.3
XCode - 12
So, my Appdelegate.swift would contain following code in didFinishLaunchingWithOptions...
FirebaseApp.configure()
And presenting SignIn UI when user presses a special button on Login view controller using below code,
if let authController = authUI?.authViewController() {
self.authController = authController
self.present(authController, animated: true, completion: nil)
}
LoginViewController.swift would have following code into viewDidload()
authUI?.delegate = self
let providers: [FUIAuthProvider] = [
FUIGoogleAuth()
]
authUI?.providers = providers
where authUI is declared as property for LoginViewController => let authUI = FUIAuth.defaultAuthUI()
I have only added Google SignIn for now so only one provider added here.
Now when my SignIn Auth UI is presented, Google SignIn button is shown and I am able to log into my Google account but when didSignInWith authDataResult is executed from FUIAuthDelegate, I get to know I am receiving an error post successful Google Account Login.
Error Domain=FUIAuthErrorDomain Code=2 "(null)" UserInfo={FUIAuthErrorUserInfoProviderIDKey=google.com, NSUnderlyingError=0x600000a08720 {Error Domain=org.openid.appauth.general Code=-15 "Audience mismatch" UserInfo={NSLocalizedDescription=Audience mismatch}}}
Is there anything I am missing?
I have already setup URL schema into info.plist and not getting any clue on how this kind of error is being generated.
Further as an update to #frank-van-puffelen,
I have confirmed proper info.plist is added or not.
My Info.Plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>847792004435-gdisqis038je5q8rr1on4ti7df09nvht.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.847792004435-gdisqis038je5q8rr1on4ti7df09nvht</string>
<key>API_KEY</key>
<string>AIzaSyDRrYM2h1wOEdKHZtOM-M904oBwrXnaO3E</string>
<key>GCM_SENDER_ID</key>
<string>847792004435</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.Speare.StashAlpha</string>
<key>PROJECT_ID</key>
<string>stash-demo-11379</string>
<key>STORAGE_BUCKET</key>
<string>stash-demo-11379.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:847792004435:ios:867e5fb8113b83b48f55a6</string>
<key>DATABASE_URL</key>
<string>https://stash-demo-11379.firebaseio.com</string>
</dict>
</plist>
Screenshot of project which is targeted for login,
We can clearly check here Project ID matches in info.plist as well as on Sign In screen.
Now in Firebase console, if we check, project ID matches and below is info.plist download button from where I can take latest info.plist.
Let me know if there is anything we can confirm info.plist does not match with target project.
This error message usually means that you're trying to sign in to a different project than what the token was minted for. So you might want to check if you have the info.plist for the correct project, and that you're set up you OAuth sign in against that same project.

Twitter Call back URL

I am working with twitter SDK to integrate with in ios app.When i follow all the step and create the customer key and put it in my app.When I run the app it show
"[TwitterKit] did encounter error with message
"Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain
Code=-1 "Callback URL not approved for this client application.
Approved callback URLs can be adjusted in your application
settings" UserInfo={NSLocalizedDescription=Callback URL
not approved for this client application. Approved callback URLs can
be adjusted in your application settings"
How to resolve this?
I had the same problem and the TwitterKit documentation is not accurate or Twitter has changed their policies. In any case, on the Twitter Apps site, the callback URL has to be set very specifically. The callback URL should be in the format:
twitterkit-{consumer/api key}://
For example:
twitterkit-128238aKjqlp123AKdasdf://
Also, this needs to be registered in your Info.plist exactly the same:
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-128238aKjqlp123AKdasdf</string>
</array>
</dict>
More documentation is listed here: https://developer.twitter.com/en/docs/basics/callback_url.html
I just added on callback url field twitterkit-<api/consumer Key>://.
If you have an apiKey like abc you should add twitterkit-abc://. This work for iOS, for Android just add twittersdk://.
To Fix this issue do as below:
[Mandatory]
Add CallbackURL into the dashboard as below format:
For iOS:
twitterkit-CONSUMERKEY://
For Android:
twittersdk://
Help Link:
https://twittercommunity.com/t/ios-twitter-login-error-code-415/107775
[ Note: Please replace your consumer key in place of words "CONSUMERKEY" in above format]
My solution: I hope it's useful.
Go to https://apps.twitter.com
Then in the "Settings" tab of your app.
Fill the "Callback URLs" form.
According to this documentation i guess you just have to enter a valid URL :
https://github.com/twitter/twitter-kit-ios/wiki/Installation
NOTE: Although the callback URL will not be requested by Twitter Kit in your app, it must be set to a valid URL for the app to work with the SDK.
Hey everyone here is a simple fix that worked for me.
Go to: https://apps.twitter.com
Go into the settings tab.
Under Terms of Service URL uncheck the box that says:
"Unable Callback Locking"
Now test your app.
Finally I found the solution for my case. Hope it'll help someone else
Put this in URL Callback field.
twittersdk://
Refer: https://github.com/twitter/twitter-kit-android/issues/135

How to open a url in safari in ios9

I'have used the following code to redirect the user to a facebook page.
NSURL *webURL = [NSURL URLWithString:#"https://m.facebook.com/icc"];
[[UIApplication sharedApplication] canOpenURL:webURL];
After updating to ios9, the above code is not working.
I have added following block in plist file. But not working.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fb-messenger-api</string>
<string>twitter</string>
<string>whatsapp</string>
<string>wechat</string>
<string>line</string>
<string>instagram</string>
<string>kakaotalk</string>
<string>mqq</string>
<string>vk</string>
<string>mqq</string>
</array>
Is anything i missed here?
There are two URL related methods that are available. canOpenURL and openURL.
canOpenURL returns a yes or no answer after checking if there is any apps installed on the device that know how to handle a given URL.
openURL is used to actually launch the URL, which will typically leave the app and open the URL in another app.
And in your case i have tried the same code its working fine for me i means in case of canOpenURL its returning YES and when i call openURL its opening the safari and yes its same what you did.
For all developers having the same issue, the solution is to add a whitelist of all URL schemes your App may need to call into the Info.plist. The key to add is LSApplicationQueriesSchemes and its value is an array with all the URL schemes.

Graph API: get nearby places

Is there a way to pass in lat/long and get a list of nearby places using Graph API 2.1?
Was looking to allow a user to check in from an iOS app, but I'd like to provide a list of nearby places so that I know which place ID to pass into the feed end point.
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/feed/
Yes, this is possible if you can get the lat/lng coordinate from your device. Have a look at https://developers.facebook.com/docs/graph-api/using-graph-api/#search
GET /search?q={query}&type=place&center={lat},{lng}&distance={distance}
You can leave the {query} blank if you don't want to narrow down your results
All Graph API search queries require an access token included in the request.
If you want to make a request to the Facebook Graph API for location searches, you do not need a user Access Token, you can use your App Token, which you'll find here: https://developers.facebook.com/apps/{app_id}/settings/advanced under Client Token
Assuming you have the facebook SDK setup correctly, all you have to do is add your App Token to your info.plist under the key FacebookClientToken. Now you should be able to make Graph Location API requests without authorizing a user!
This is what your info.plist should look like:
<key>FacebookAppID</key>
<string>{{APP_ID}}</string>
<key>FacebookClientToken</key>
<string>{{CLIENT_TOKEN}}</string>
<key>FacebookDisplayName</key>
<string>{{APP_NAME}}</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
Obviously, change anything between the {{ }} to the appropriate value.

"Cannot Open Page" Error when doing Facebook single sign on in Appcelerator Titanium

I have setup a view in my appcelerator titanium app to be nearly identical to the one in the kitchen sink demo for facebook login. I want to use single sign on for IOS:
//LoginView Component Constructor
function LoginView() {
//create object instance, a parasitic subclass of Observable
var self = Ti.UI.createView();
// APP ID BELOW IS CHANGED FOR DEMO PURPOSES
Titanium.Facebook.appid = "111111111111111";
Titanium.Facebook.permissions = ['email', 'publish_actions'];
// ENABLE SINGLE SIGN ON
Titanium.Facebook.forceDialogAuth = false;
self.add(Titanium.Facebook.createLoginButton({
style:Ti.Facebook.BUTTON_STYLE_WIDE,
bottom:30
}));
return self;
}
module.exports = LoginView;
When clicking the login button, it successfully opens the facebook login dialog in safari and I login. Then when it tries to take me back to the app, I get the error:
Cannot Open the Page Safari cannot open the page because the address
is invalid
Very similar code works correctly in the kitchen sink app, and also disabling single sign on makes logging in through facebook work correctly in my app.
All I have for the settings in the facebook app is:
Facebook Login - Enabled
Am I missing anything from the settings?
Figured it out:
In my facebook app settings (on developers.facebook.com), I set the bundle Id to the same id as my app in Appcelerator.
Based on the q & a:
Copied Info.plist from build/iphone/ into the root of the application.
Added the xml element fb111111111111111 below under app to Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.mycompany.app</string>
<key>CFBundleURLSchemes</key>
<array>
<string>app</string>
<string>fb111111111111111</string>
</array>
</dict>
</array>
Where 111111111111111 is changed to the id of the app