So I already have Google SignIn implemented properly - all I want to do now is to sign the user in and grab all of their contacts' information. However, there doesn't really seem to be proper documentation. I know that I have to query https://www.google.com/m8/feeds/contacts/default/full, but I don't know where that query would go or how it would be structured. Any ideas?
Asked
Active
Viewed 437 times
0
-
https://stackoverflow.com/questions/40163529/integrate-google-contacts-api-into-my-swift-3-app/54710237#54710237 – Naresh Feb 15 '19 at 13:25
1 Answers
0
I don't know where that query would go or how it would be structured. Any ideas?
This, https://www.google.com/m8/feeds/contacts/default/full
, is called an HTTP request. You will send a 'GET' request to the server and if successful, the server sends a response back.
One of many ways to do this is to use XMLHttpRequest in Swift.
snippet:
// Prepare the HTTP request object:
let request = CkoHttpRequest()
request.Path = "/xmlEcho.asp"
// This example will use the "PUT" HTTP request method
// (also known as HTTP verb)
request.HttpVerb = "PUT"
request.ContentType = "text/xml"
request.Charset = "utf-8"
success = request.LoadBodyFromString(xmlStr, charset: "utf-8")
Based on this thread, you can also make use of these methods:
Using NSURLSession
let url = NSURL(string: "http://www.stackoverflow.com") let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in print(NSString(data: data!, encoding: NSUTF8StringEncoding)) } task.resume()
Using NSURLConnection
First, initialize an NSURL and an NSURLRequest:
let url = NSURL(string: "http://www.stackoverflow.com")
let request = NSURLRequest(URL: url!)
Then, you can load the request asynchronously with:
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {(response, data, error) in
print(NSString(data: data!, encoding: NSUTF8StringEncoding))
}
Or you can initialize an NSURLConnection:
let connection = NSURLConnection(request: request, delegate:nil, startImmediately: true)
This is a lot to absorb if it's your first time. Hope this helps.

Community
- 1
- 1

ReyAnthonyRenacia
- 17,219
- 5
- 37
- 56