How to fetch google contacts into an iOS application - ios

I read the below link and now I understood that I need to make an api call to fetch the contacts. As I am new to Swift3 could someone guide me how to do this. I read somewhere that Almofire and Swifty json would help and I also read GData also will help. I am little confused. Please guide me.
Google Contacts API

You might want to try Google Sign-In for iOS, get users into your apps quickly and securely, using a registration system they already use and trust—their Google account. This Google Sign-in videos - series #1, series #2 and series #3 will help you understand the implementation of Google SignIn in iOS, how do you use Google Sign in on iOS with another service like Google Drive? and more.
Here are some tutorials and reference that can help:
Integrate Google Signin SDK In iOS Application Using Swift
How to Integrate Google Sign In into Your iOS Apps
Requesting additional scopes after sign-in
Invite friends from Gmail (This tutorial use a gmail contact scope rather than the google plus contacts) PS. not an iOS tutorial
Lastly here are some related SO question for refrence - How to fetch gmail Contacts in iOS application using google contacts api? and Get Google contacts using API on iOS
Hope this helps.

I was actually stuck on this too and couldn't find a solution but I ended up figuring it out. You first need to authenticate with Google Sign In and then pass the accessToken into this endpoint:
let urlString = ("https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=5000&access_token=\(GIDSignIn.sharedInstance().currentUser.authentication.accessToken!)")
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url, completionHandler: {
(data, response, error) in
if(error != nil){
print("error")
}else{
do{
let json = try JSONSerialization.jsonObject(with: data!, options:[]) as! [String : AnyObject]
//parse JSON
}catch let error as NSError{
print(error)
}
}
}).resume()

Related

iOS - GitHub Firebase Authentication

I'm currently trying to implement GitHub Authentication via Firebase in an iOS app.
I've read through the docs and figured out what I have to do. I'm having trouble though, in implementing the communication between my app and the WebView where I authorize the application to get user's data. I currently have this code:
let url = urlComponents.url! // https://github.com/login/oauth/authorize + scope
// Not quite sure if I should use open(_:options:completionHandler:) to handle this operation.
guard UIApplication.shared.canOpenURL(url) else {
return
}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
What this code does is bring the user to the browser with the GitHub authorization screen, type the password and then a blank screen shows up. Inspecting the URL in this blank screen, I've found out that it contains the parameter it should have, but I'm not quite sure how to pass this parameter to my code so I can proceed with the authentication.
Firebase doc says I should implement a Custom URL scheme to handle the OAuth callback, but I'm not sure how to do it.
Solved, solution was to edit GitHub's Authorization callback URL to have my custom URL scheme and then proceed through the documentation flow.

Implementing Steam OpenID for iOS

I'm trying to implement Steam Authentication via OpenID for iOS using this framework. I already translated the demo to Swift 3 and made it work with Google. Now I'm trying to get it to work with Steam and I don't know where to find some of its configuration. To make the app work with Google I use this information:
let kClientID = "xxxxx.apps.googleusercontent.com"
let KRedirectURI = URL(string: "com.googleusercontent.apps.xxxxxx:/oauthredirect")
let kIssuer = URL(string: "https://accounts.google.com")
I've being looking in their dev wiki but so far I could just find how to get the API key. Would you have this information? It is my first contact with OpenID and I'm a bit lost.
Thanks for any help

Swift Google Calendar Account Signout

I just started to learn Swift recently and I implemented the sample code that Google gives us to create a calendar. However, I would also like to know how to signout of an account to switch to another calendar but I can't seem to figure it out. Could someone give me some pointers?
Thanks for your help in advance! :-)
Tim
Google docs has a revoking a token guide for OAuth 2.0.
You can use request using HTTP/REST:
curl https://accounts.google.com/o/oauth2/revoke?token={token}
If you're not familiar with HTTP request in Swift, try the following guides in this thread using NSURLConnection.
let url = NSURL(string: "https://accounts.google.com/o/oauth2/revoke?token={token}")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
print(NSString(data: data!, encoding: NSUTF8StringEncoding))
}
task.resume()

Fetch Unfollower Instagram api swift

Can i fetch details of unfollower of Instagram user using instagram api?
If it's possible then how can i do it????
I used relationship endpoint to do it
https://api.instagram.com/v1/users/{user-id}/relationship?access_token=ACCESS-TOKEN
let newJson1 = JSON(data: NSData(contentsOfURL: NSURL(string: "https://api.instagram.com/v1/users/\(self.id)/relationship?access_token=\(self.accessToken)")!)!, options: NSJSONReadingOptions.AllowFragments, error: nil)
print(newJson1)
but none of the results found....
Do you have some advices? Thanks
#John Instagram limits the api access. For that you have to approve your app permission from the sandbox. Once the Instagram approves your permission, then you can access of the relevant data. Approving permission can be done by submitting your app to Instagram.

Authentication with Twitter using the Twitter access token on Azure (using iOS Twitter reverse Auth)

I'm currently working on an iOS app which will (if I can figure out this problem) use Azure as backend. The user is supposed to login with their iOS account which they already setup on their iOS device. I than use reverse authentication (https://dev.twitter.com/docs/ios/using-reverse-auth) to get the user's access token and I would like to use said access token to login the user.
I tried using (Swift snippet)
let tokenDictionary = ["access_token": "<token-I-got>"];
client.loginWithProvider("twitter", token: tokenDictionary.bridgeToObjectiveC(), completion: {(user: MSUser!, error: NSError?) in
if let user = user? {
print(user.userId)
} else if let error = error? {
print(error)
}
})
but the only thing the API returns is:
POST of Twitter token is not supported.
Any ideas how I could get this to work or do I have to switch away from Azure to something different? (And using the webview for login is not an option, as we have this nice already accounts on iOS already setup with the credentials).
Thanks for helping.
This feature is not currently supported by Azure Mobile Services. You can upvote the feature request here.

Resources