Pinterest authentication fails: -canOpenURL: failed for URL: "pinterestsdk.v1://oauth - ios

I'm trying to implement authentication between my Swift app and Pinterest. I can get the app to open pinterest authentication page in Safari but the after I enter my Pinterest username/password and press OKAY, the app throws the following error message:
CODE:
PDKClient.configureSharedInstanceWithAppId("************")//replaced appid with ****
let permission = [PDKClientReadPublicPermissions]
PDKClient.sharedInstance().authenticateWithPermissions(permission, fromViewController: self, withSuccess: { (pdk :PDKResponseObject!) -> Void in print("success PDKResponseObject: \(pdk)")
}) { (err :NSError!) -> Void in
print("errori tuli: error NSError: \(err)")
}
ERROR:
-canOpenURL: failed for URL: "pinterestsdk.v1://oauth/?app_name=MyApp&permissions=read_public&client_id=4853625080298613350" - error: "(null)"
I can't figure out what's wrong. ALL HELP APPRECIATED!

The answer lies here at Gibhub. In short, I was editing the wring plist.info. https://github.com/pinterest/ios-pdk/issues/117#issuecomment-244440823

Related

linkedin get profile - Request failed: forbidden (403) error swift

I am facing problem with "https://api.linkedin.com/v2/me" api of LinkedIn. Code was working good when I was using v1 api. I have updated my code for version 2 api for linkedIn authentication and When I tried to get profile with api "https://api.linkedin.com/v2/me" I am getting error Request failed: forbidden (403). I don't know how to resolve it.
Here is my code:
let linkedinHelper = LinkedinSwiftHelper(configuration: LinkedinSwiftConfiguration(clientId: Constant.Key.kLinkedInClientId, clientSecret: Constant.Key.kLinkedInClientSecret, state: Constant.Key.kLinkedInState, permissions: ["r_basicprofile", "r_emailaddress"], redirectUrl: Constant.Key.kLinkedInRedirectURL),nativeAppChecker: WebLoginOnly())
linkedinHelper.authorizeSuccess({ (token) in
print(token)
let url = "https://api.linkedin.com/v2/me"
linkedinHelper.requestURL(url, requestType: LinkedinSwiftRequestGet, success: { (response) -> Void in
print(response)
}) {(error) -> Void in
print(error.localizedDescription)
//handle the error
}
I've set URL scheme in info.plist as well.
You have to pass key in oauth2_access_token
Example:
https://api.linkedin.com/v2/me?oauth2_access_token={linkedin_key}
Edit:-
Also in permission need to set "r_liteprofile" instead of "r_basicprofile". To change permission worked for me.

LinkedIn login with custom token ( ERROR_INVALID_CUSTOM_TOKEN )

I am trying to login with LinkedIn using the native app and the LinkedIn SDK. So far I can login using the web if the LinkedIn app is not installed. I can also login with LinkedIn and get a token in return. But when I try to authenticate with Firebase I get this error:
Optional(Error Domain=FIRAuthErrorDomain Code=17000 "The custom token
format is incorrect. Please check the documentation." UserInfo=
{NSLocalizedDescription=The custom token format is incorrect. Please
check the documentation., error_name=ERROR_INVALID_CUSTOM_TOKEN})
This is my code:
// App installed
let permissions = [LISDK_BASIC_PROFILE_PERMISSION,LISDK_EMAILADDRESS_PERMISSION]
LISDKSessionManager.createSession(withAuth: permissions, state: nil, showGoToAppStoreDialog: true, successBlock: { (returnState) -> Void in
LISDKAPIHelper.sharedInstance().getRequest("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,public-profile-url,industry,positions,location)?format=json", success: { (response) -> Void in
if let data = response?.data.data(using: String.Encoding.utf8) {
if let dictResponse = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers){
let token = LISDKSessionManager.sharedInstance().session.accessToken.accessTokenValue
Auth.auth().signIn(withCustomToken: token! ) { (user, error) in
print(user!)
print(error!)
}
}
}
}, error: { (error) -> Void in
print("LINKEDIN error\(String(describing: error))")
})
}) { (error) -> Void in
print("error login linkedin")
}
The token I am sending to Firebase is a String, so that should be okay. I must be missing something. But what ?
The problem was my misunderstanding. I thought I could use the Linkedin token directly. It has to go to a webservice that uses the Firebase admin user to generate the token.

iOS error with Firebase Auth Sign In using Twitter credentials

I have a iOS Firebase app that supports Twitter login, but occasionally the signIn(with: credential call randomly fails and I can't figure out why.
First the user signs in with Twitter (which never fails), then I use the Twitter session to get the credentials, and then I use those credentials to sign in with Firebase which sometimes fails.
Here's the complete code
func twitterLogin(_ done:#escaping (_ user: FIRUser?, _ err: Error?) -> Void) {
Twitter.sharedInstance().logIn() { session, error in
guard error == nil else {
done(nil, error)
return
}
let credential = FIRTwitterAuthProvider.credential(withToken: session!.authToken, secret: session!.authTokenSecret)
FIRAuth.auth()?.signIn(with: credential, completion: { (signUser, error) in
//User is signed in
// ERROR OCCURS HERE. ANY HELP WOULD BE GREATLY APPRECIATED
done(signUser, error)
})
}
}
Here's the exact error message I'm getting.
UserInfo={NSUnderlyingError=0x600000442c10 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
code = 400;
errors = (
{
domain = global;
message = "Network error while to fetch VERIFY_CREDENTIAL from TWITTER.";
reason = invalid;
}
);
message = "Network error while to fetch VERIFY_CREDENTIAL from TWITTER.";
}}}, error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.})
I've tried to specifically search for the error message I'm getting "Network error while to fetch VERIFY_CREDENTIAL from TWITTER." but I can't find any solution. I found some posts which I believe were in Japanese but I couldn't understand their solution.
I even looked at Firebases iOS Auth errors here
https://firebase.google.com/docs/auth/ios/errors
but the error key FIRAuthErrorUserInfoDeserializedResponseKey isn't even listed as a possible error for signInWithCredential:completion:
I'm seeing the same error. Example at codepen:
https://codepen.io/mosse/pen/KmGMap
<button class="login">login</button>
<script src="https://www.gstatic.com/firebasejs/4.0.0/firebase.js"></script>
<script>
var config = {
apiKey: "AIzaSyDfJ5KuDofcZpahzl4H3XTl4f6R65gUyrQ",
authDomain: "authtest-3a944.firebaseapp.com",
projectId: "authtest-3a944",
};
firebase.initializeApp(config);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".login").click(function(){
var providerObj = new firebase.auth.TwitterAuthProvider();
firebase.auth().signInWithPopup(providerObj)
.then(result => {
console.log('success')
console.log(result.user)
})
.catch( err => {
console.log('failure')
console.log(err.message)
})
});
});
</script>
Firebase support suggest the cause is due to an unreliable Twitter endpoint, but haven't suggested any solution.
An older project using Firebase 2.3.2 does not replicate the error, which suggests that there should be a Firebase solution to me.

Error code 403 when using guest authentication with TwitterKit iOS for getting user timeline

I am using Fabric's twitter kit for getting a username's tweets in my iOS application by making a request to the REST API endpoint "https://api.twitter.com/1.1/statuses/user_timeline.json"
I am have correctly set up my "consumer key" and "consumer secret key" as provided by the Fabric app in my AppDelegate and info.plist , but I repeatedly get the following error message -
Error: Optional(Error Domain=TwitterAPIErrorDomain Code=200 "Request
failed: forbidden (403)"
UserInfo={NSErrorFailingURLKey=https://api.twitter.com/1.1/guest/activate.json,
NSLocalizedDescription=Request failed: forbidden (403),
NSLocalizedFailureReason=Twitter API error : Forbidden. (code 200)})
My code is as under follows -
Twitter.sharedInstance().startWithConsumerKey(TWITTER_CONSUMER_KEY, consumerSecret: TWITTER_CONSUMER_KEY_SECRET)
Fabric.with([Twitter.sharedInstance()])
let userId = Twitter.sharedInstance().sessionStore.session()?.userID
let client = TWTRAPIClient.init(userID: userId)
let params = ["screen_name": twitterUsername, "count" : "10"]
var clientError : NSError?
let request = client.URLRequestWithMethod("GET", URL: TWITTER_TIMELINE_ENDPOINT, parameters: params, error: &clientError)
client.sendTwitterRequest(request) { (response, data, connectionError) -> Void in
if(connectionError == nil) {
self.twitterJson = self.nsdataToJSON(data!)!
self.constructTweetView(self.twitterJson)
}
else {
print("Error: \(connectionError)")
}
I am on the most recent version of TwitterKit(>2.0)
How can I go about resolving this ?
Thanks!
Add key in exception domains as shown in info.plist. Following fixed bug for me.

Facebook Pages API Swift

I'm new in programming in swift. I'm trying to read Facebook pages posts(wall) from a public page and show the content(images and messages) in my app without users login. I've already set up the app with Facebook SDK (plist, bridging-Header.h etc...). I know I must open a session and pass a valid access token to the Facebook server. But I can't understand how....
below my viewDidLoad
let request = "/(pageID)?fields=id,posts"
FBRequestConnection.startWithGraphPath(request, completionHandler: {(connection: FBRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if (error? != nil){
NSLog("error = \(error)")
}else{
println(result)
}
} as FBRequestHandler)
I get this error:
An open FBSession must be specified for calls to this endpoint.
com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 104;
message = "An access token is required to request this resource.";
type = OAuthException;
};
};
code = 400;
}}
i think i need to open a session in AppDelegate and so I can make the request I've also read the Facebook documentation but I haven't found the answer.
Please help me. Thank you!!!

Resources